Can't handle offset and scale if rip-relative addressing is to be used.
authorEvan Cheng <evan.cheng@apple.com>
Wed, 1 Aug 2007 23:46:47 +0000 (23:46 +0000)
committerEvan Cheng <evan.cheng@apple.com>
Wed, 1 Aug 2007 23:46:47 +0000 (23:46 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40703 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86ISelLowering.cpp

index 939ddf819a6dc654ede039224907a5206950fc2b..91da4c0b6c8970004b2aaa9b35df2665312ca0cd 100644 (file)
@@ -4449,14 +4449,18 @@ bool X86TargetLowering::isLegalAddressingMode(const AddrMode &AM,
     return false;
   
   if (AM.BaseGV) {
-    // X86-64 only supports addr of globals in small code model.
-    if (Subtarget->is64Bit() &&
-        getTargetMachine().getCodeModel() != CodeModel::Small)
-      return false;
-    
-    // We can only fold this if we don't need a load either.
+    // We can only fold this if we don't need an extra load.
     if (Subtarget->GVRequiresExtraLoad(AM.BaseGV, getTargetMachine(), false))
       return false;
+
+    // X86-64 only supports addr of globals in small code model.
+    if (Subtarget->is64Bit()) {
+      if (getTargetMachine().getCodeModel() != CodeModel::Small)
+        return false;
+      // If lower 4G is not available, then we must use rip-relative addressing.
+      if (AM.BaseOffs || AM.Scale > 1)
+        return false;
+    }
   }
   
   switch (AM.Scale) {