[llvm-commits] [llvm] r68778 - in /llvm/trunk: lib/Target/X86/X86ISelDAGToDAG.cpp test/CodeGen/X86/tls10.ll test/CodeGen/X86/tls15.ll test/CodeGen/X86/tls2.ll test/CodeGen/X86/tls6.ll test/CodeGen/X86/tls8.ll

Rafael Espindola rafael.espindola at gmail.com
Fri Apr 10 03:09:40 PDT 2009


Author: rafael
Date: Fri Apr 10 05:09:34 2009
New Revision: 68778

URL: http://llvm.org/viewvc/llvm-project?rev=68778&view=rev
Log:
Don't fold a load if the other operand is a TLS address.

With this we generate

movl    %gs:0, %eax
leal    i at NTPOFF(%eax), %eax

instead of

movl    $i at NTPOFF, %eax
addl    %gs:0, %eax


Added:
    llvm/trunk/test/CodeGen/X86/tls15.ll
Modified:
    llvm/trunk/lib/Target/X86/X86ISelDAGToDAG.cpp
    llvm/trunk/test/CodeGen/X86/tls10.ll
    llvm/trunk/test/CodeGen/X86/tls2.ll
    llvm/trunk/test/CodeGen/X86/tls6.ll
    llvm/trunk/test/CodeGen/X86/tls8.ll

Modified: llvm/trunk/lib/Target/X86/X86ISelDAGToDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelDAGToDAG.cpp?rev=68778&r1=68777&r2=68778&view=diff

==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelDAGToDAG.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelDAGToDAG.cpp Fri Apr 10 05:09:34 2009
@@ -322,6 +322,8 @@
     case ISD::AND:
     case ISD::OR:
     case ISD::XOR: {
+      SDValue Op1 = U->getOperand(1);
+
       // If the other operand is a 8-bit immediate we should fold the immediate
       // instead. This reduces code size.
       // e.g.
@@ -332,9 +334,25 @@
       // addl 4(%esp), %eax
       // The former is 2 bytes shorter. In case where the increment is 1, then
       // the saving can be 4 bytes (by using incl %eax).
-      if (ConstantSDNode *Imm = dyn_cast<ConstantSDNode>(U->getOperand(1)))
+      if (ConstantSDNode *Imm = dyn_cast<ConstantSDNode>(Op1))
         if (Imm->getAPIntValue().isSignedIntN(8))
           return false;
+
+      // If the other operand is a TLS address, we should fold it instead.
+      // This produces
+      // movl    %gs:0, %eax
+      // leal    i at NTPOFF(%eax), %eax
+      // instead of
+      // movl    $i at NTPOFF, %eax
+      // addl    %gs:0, %eax
+      // if the block also has an access to a second TLS address this will save
+      // a load.
+      // FIXME: This is probably also true for non TLS addresses.
+      if (Op1.getOpcode() == X86ISD::Wrapper) {
+        SDValue Val = Op1.getOperand(0);
+        if (Val.getOpcode() == ISD::TargetGlobalTLSAddress)
+          return false;
+      }
     }
     }
 
@@ -1170,13 +1188,16 @@
                                     SDValue &Base, SDValue &Scale,
                                     SDValue &Index, SDValue &Disp) {
   X86ISelAddressMode AM;
-  if (MatchAddress(N, AM))
-    return false;
 
-  //Is it better to set AM.Segment before calling MatchAddress to
-  //prevent it from adding a segment?
-  if (AM.Segment.getNode())
+  // Set AM.Segment to prevent MatchAddress from using one. LEA doesn't support
+  // segments.
+  SDValue Copy = AM.Segment;
+  SDValue T = CurDAG->getRegister(0, MVT::i32);
+  AM.Segment = T;
+  if (MatchAddress(N, AM))
     return false;
+  assert (T == AM.Segment);
+  AM.Segment = Copy;
 
   MVT VT = N.getValueType();
   unsigned Complexity = 0;

Modified: llvm/trunk/test/CodeGen/X86/tls10.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/tls10.ll?rev=68778&r1=68777&r2=68778&view=diff

==============================================================================
--- llvm/trunk/test/CodeGen/X86/tls10.ll (original)
+++ llvm/trunk/test/CodeGen/X86/tls10.ll Fri Apr 10 05:09:34 2009
@@ -1,6 +1,6 @@
 ; RUN: llvm-as < %s | llc -march=x86 -mtriple=i386-linux-gnu > %t
-; RUN: grep {movl	\$i at NTPOFF, %eax} %t
-; RUN: grep {addl	%gs:0, %eax} %t
+; RUN: grep {movl	%gs:0, %eax} %t
+; RUN: grep {leal	i at NTPOFF(%eax), %eax} %t
 
 @i = external hidden thread_local global i32
 

Added: llvm/trunk/test/CodeGen/X86/tls15.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/tls15.ll?rev=68778&view=auto

==============================================================================
--- llvm/trunk/test/CodeGen/X86/tls15.ll (added)
+++ llvm/trunk/test/CodeGen/X86/tls15.ll Fri Apr 10 05:09:34 2009
@@ -0,0 +1,14 @@
+; RUN: llvm-as < %s | llc -march=x86 -mtriple=i386-linux-gnu > %t
+; RUN: grep {movl	%gs:0, %eax} %t | count 1
+; RUN: grep {leal	i at NTPOFF(%eax), %ecx} %t
+; RUN: grep {leal	j at NTPOFF(%eax), %eax} %t
+
+ at i = thread_local global i32 0
+ at j = thread_local global i32 0
+
+define void @f(i32** %a, i32** %b) {
+entry:
+	store i32* @i, i32** %a, align 8
+	store i32* @j, i32** %b, align 8
+	ret void
+}

Modified: llvm/trunk/test/CodeGen/X86/tls2.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/tls2.ll?rev=68778&r1=68777&r2=68778&view=diff

==============================================================================
--- llvm/trunk/test/CodeGen/X86/tls2.ll (original)
+++ llvm/trunk/test/CodeGen/X86/tls2.ll Fri Apr 10 05:09:34 2009
@@ -1,6 +1,6 @@
 ; RUN: llvm-as < %s | llc -march=x86 -mtriple=i386-linux-gnu > %t
-; RUN: grep {movl	\$i at NTPOFF, %eax} %t
-; RUN: grep {addl	%gs:0, %eax} %t
+; RUN: grep {movl	%gs:0, %eax} %t
+; RUN: grep {leal	i at NTPOFF(%eax), %eax} %t
 
 @i = thread_local global i32 15
 

Modified: llvm/trunk/test/CodeGen/X86/tls6.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/tls6.ll?rev=68778&r1=68777&r2=68778&view=diff

==============================================================================
--- llvm/trunk/test/CodeGen/X86/tls6.ll (original)
+++ llvm/trunk/test/CodeGen/X86/tls6.ll Fri Apr 10 05:09:34 2009
@@ -1,6 +1,6 @@
 ; RUN: llvm-as < %s | llc -march=x86 -mtriple=i386-linux-gnu > %t
-; RUN: grep {movl	\$i at NTPOFF, %eax} %t
-; RUN: grep {addl	%gs:0, %eax} %t
+; RUN: grep {movl	%gs:0, %eax} %t
+; RUN: grep {leal	i at NTPOFF(%eax), %eax} %t
 
 @i = internal thread_local global i32 15
 

Modified: llvm/trunk/test/CodeGen/X86/tls8.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/tls8.ll?rev=68778&r1=68777&r2=68778&view=diff

==============================================================================
--- llvm/trunk/test/CodeGen/X86/tls8.ll (original)
+++ llvm/trunk/test/CodeGen/X86/tls8.ll Fri Apr 10 05:09:34 2009
@@ -1,6 +1,6 @@
 ; RUN: llvm-as < %s | llc -march=x86 -mtriple=i386-linux-gnu > %t
-; RUN: grep {movl	\$i at NTPOFF, %eax} %t
-; RUN: grep {addl	%gs:0, %eax} %t
+; RUN: grep {movl	%gs:0, %eax} %t
+; RUN: grep {leal	i at NTPOFF(%eax), %eax} %t
 
 @i = hidden thread_local global i32 15
 





More information about the llvm-commits mailing list