Try again. Allow call to immediate address for ELF or when in static relocation mode.
authorEvan Cheng <evan.cheng@apple.com>
Wed, 20 May 2009 04:53:57 +0000 (04:53 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Wed, 20 May 2009 04:53:57 +0000 (04:53 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@72160 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86InstrInfo.td
lib/Target/X86/X86Subtarget.cpp
lib/Target/X86/X86Subtarget.h
test/CodeGen/X86/call-imm.ll

index 10eddf0f110d88cecf8c615a39e19e3322e0142a..84c357308a59ebfc92d4e6604be80c6a23fd98cf 100644 (file)
@@ -234,9 +234,9 @@ def In64BitMode  : Predicate<"Subtarget->is64Bit()">;
 def SmallCode    : Predicate<"TM.getCodeModel() == CodeModel::Small">;
 def NotSmallCode : Predicate<"TM.getCodeModel() != CodeModel::Small">;
 def IsStatic     : Predicate<"TM.getRelocationModel() == Reloc::Static">;
-def IsNotPIC     : Predicate<"TM.getRelocationModel() != Reloc::PIC_">;
 def OptForSpeed  : Predicate<"!OptForSize">;
 def FastBTMem    : Predicate<"!Subtarget->isBTMemSlow()">;
+def CallImmAddr  : Predicate<"Subtarget->IsLegalToCallImmediateAddr(TM)">;
 
 //===----------------------------------------------------------------------===//
 // X86 Instruction Format Definitions.
@@ -562,8 +562,7 @@ let isCall = 1 in
               XMM8, XMM9, XMM10, XMM11, XMM12, XMM13, XMM14, XMM15, EFLAGS],
       Uses = [ESP] in {
     def CALLpcrel32 : Ii32<0xE8, RawFrm, (outs), (ins i32imm:$dst,variable_ops),
-                           "call\t${dst:call}", [(X86call imm:$dst)]>,
-                      Requires<[In32BitMode, IsNotPIC]>;
+                           "call\t${dst:call}", []>;
     def CALL32r     : I<0xFF, MRM2r, (outs), (ins GR32:$dst, variable_ops),
                         "call\t{*}$dst", [(X86call GR32:$dst)]>;
     def CALL32m     : I<0xFF, MRM2m, (outs), (ins i32mem:$dst, variable_ops),
@@ -3342,6 +3341,8 @@ def : Pat<(X86call (i32 tglobaladdr:$dst)),
           (CALLpcrel32 tglobaladdr:$dst)>;
 def : Pat<(X86call (i32 texternalsym:$dst)),
           (CALLpcrel32 texternalsym:$dst)>;
+def : Pat<(X86call (i32 imm:$dst)),
+          (CALLpcrel32 imm:$dst)>, Requires<[CallImmAddr]>;
 
 // X86 specific add which produces a flag.
 def : Pat<(addc GR32:$src1, GR32:$src2),
index df1f7db85fcf71dea38f5c3468aae1aa61c685a9..d54ccb37e3b411be949749bb8502aba20cdf1426 100644 (file)
@@ -74,8 +74,8 @@ bool X86Subtarget::GVRequiresExtraLoad(const GlobalValue* GV,
 /// cases where GVRequiresExtraLoad is true.  Some variations of PIC require
 /// a register, but not an extra load.
 bool X86Subtarget::GVRequiresRegister(const GlobalValue *GV,
-                                       const TargetMachine& TM,
-                                       bool isDirectCall) const
+                                      const TargetMachine& TM,
+                                      bool isDirectCall) const
 {
   if (GVRequiresExtraLoad(GV, TM, isDirectCall))
     return true;
@@ -99,6 +99,14 @@ const char *X86Subtarget::getBZeroEntry() const {
   return 0;
 }
 
+/// IsLegalToCallImmediateAddr - Return true if the subtarget allows calls
+/// to immediate address.
+bool X86Subtarget::IsLegalToCallImmediateAddr(const TargetMachine &TM) const {
+  if (Is64Bit)
+    return false;
+  return isTargetELF() || TM.getRelocationModel() == Reloc::Static;
+}
+
 /// getSpecialAddressLatency - For targets where it is beneficial to
 /// backschedule instructions that compute addresses, return a value
 /// indicating the number of scheduling cycles of backscheduling that
index ded26e891e16c62e8f39eef0ff72b398a7c6d83b..abf1e814175f4ff5c25cf02cb4cd8e63191c9b1f 100644 (file)
@@ -189,6 +189,10 @@ public:
   bool GVRequiresRegister(const GlobalValue* GV, const TargetMachine& TM,
                            bool isDirectCall) const;
 
+  /// IsLegalToCallImmediateAddr - Return true if the subtarget allows calls
+  /// to immediate address.
+  bool IsLegalToCallImmediateAddr(const TargetMachine &TM) const;
+
   /// This function returns the name of a function which has an interface
   /// like the non-standard bzero function, if such a function exists on
   /// the current subtarget and it is considered prefereable over
index b22b65eaea270d605b9260da0a75944f574a9c02..c39c6c09292f8fcae2c371a303305a1db8769c7c 100644 (file)
@@ -1,4 +1,5 @@
-; RUN: llvm-as < %s | llc -march=x86    | grep {call.*12345678}
+; RUN: llvm-as < %s | llc -mtriple=i386-darwin-apple -relocation-model=static | grep {call.*12345678}
+; RUN: llvm-as < %s | llc -mtriple=i386-pc-linux -relocation-model=dynamic-no-pic | grep {call.*12345678}
 ; RUN: llvm-as < %s | llc -march=x86 -relocation-model=pic | not grep {call.*12345678}
 
 ; Call to immediate is not safe on x86-64 unless we *know* that the