In the initial exec mode we always do a load to find the address of a variable.
authorRafael Espindola <rafael.espindola@gmail.com>
Fri, 29 Jun 2012 04:22:35 +0000 (04:22 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Fri, 29 Jun 2012 04:22:35 +0000 (04:22 +0000)
Before this patch in pic 32 bit code we would add the global base register
and not load from that address. This is a really old bug, but before the
introduction of the tls attributes we would never select initial exec for
pic code.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@159409 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86ISelLowering.cpp
test/CodeGen/X86/tls-pie.ll

index 1a60ce366ead97b78480787ebb90af8eae648d6d..e6a0df7b0439135660495f65d830d34f2e7b6611 100644 (file)
@@ -7451,11 +7451,11 @@ static SDValue LowerToTLSExecModel(GlobalAddressSDNode *GA, SelectionDAG &DAG,
       Offset = DAG.getNode(ISD::ADD, dl, PtrVT,
                           DAG.getNode(X86ISD::GlobalBaseReg, DebugLoc(), PtrVT),
                            Offset);
-    } else {
-      Offset = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Offset,
-                           MachinePointerInfo::getGOT(), false, false, false,
-                           0);
     }
+
+    Offset = DAG.getLoad(PtrVT, dl, DAG.getEntryNode(), Offset,
+                         MachinePointerInfo::getGOT(), false, false, false,
+                         0);
   }
 
   // The address of the thread local variable is the add of the thread
index 5cb3866f71c44c7462f22a59b3c3737468e9a266..8269c43b9a7678f0c409a9383868bc140c6da8fd 100644 (file)
@@ -40,7 +40,8 @@ define i32 @f3() {
 ; X32-NEXT: popl %eax
 ; X32-NEXT: .Ltmp{{[0-9]+}}:
 ; X32-NEXT: addl $_GLOBAL_OFFSET_TABLE_+(.Ltmp{{[0-9]+}}-.L{{[0-9]+}}$pb), %eax
-; X32-NEXT: movl %gs:i2@GOTNTPOFF(%eax), %eax
+; X32-NEXT: movl i2@GOTNTPOFF(%eax), %eax
+; X32-NEXT: movl %gs:(%eax), %eax
 ; X32-NEXT: ret
 ; X64: f3:
 ; X64:      movq i2@GOTTPOFF(%rip), %rax
@@ -56,11 +57,11 @@ define i32* @f4() {
 ; X32: f4:
 ; X32:      calll .L{{[0-9]+}}$pb
 ; X32-NEXT: .L{{[0-9]+}}$pb:
-; X32-NEXT: popl %eax
+; X32-NEXT: popl %ecx
 ; X32-NEXT: .Ltmp{{[0-9]+}}:
-; X32-NEXT: addl $_GLOBAL_OFFSET_TABLE_+(.Ltmp{{[0-9]+}}-.L{{[0-9]+}}$pb), %eax
-; X32-NEXT: leal i2@GOTNTPOFF(%eax), %eax
-; X32-NEXT: addl %gs:0, %eax
+; X32-NEXT: addl $_GLOBAL_OFFSET_TABLE_+(.Ltmp{{[0-9]+}}-.L{{[0-9]+}}$pb), %ecx
+; X32-NEXT: movl %gs:0, %eax
+; X32-NEXT: addl i2@GOTNTPOFF(%ecx), %eax
 ; X32-NEXT: ret
 ; X64: f4:
 ; X64:      movq %fs:0, %rax