diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2009-04-10 10:09:34 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2009-04-10 10:09:34 +0000 |
commit | bb834f0929434410e63c7e64de39df642448b386 (patch) | |
tree | dbca9631b61bd5fe4dd4d7c631ad4df2f57996bd /llvm/lib | |
parent | 1aced0c9d242ea7446bdf9196b45caa2f41348e9 (diff) | |
download | bcm5719-llvm-bb834f0929434410e63c7e64de39df642448b386.tar.gz bcm5719-llvm-bb834f0929434410e63c7e64de39df642448b386.zip |
Don't fold a load if the other operand is a TLS address.
With this we generate
movl %gs:0, %eax
leal i@NTPOFF(%eax), %eax
instead of
movl $i@NTPOFF, %eax
addl %gs:0, %eax
llvm-svn: 68778
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Target/X86/X86ISelDAGToDAG.cpp | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp index 2cd6f74f27e..1b9572cc412 100644 --- a/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp +++ b/llvm/lib/Target/X86/X86ISelDAGToDAG.cpp @@ -322,6 +322,8 @@ bool X86DAGToDAGISel::IsLegalAndProfitableToFold(SDNode *N, SDNode *U, 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 @@ bool X86DAGToDAGISel::IsLegalAndProfitableToFold(SDNode *N, SDNode *U, // 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@NTPOFF(%eax), %eax + // instead of + // movl $i@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 @@ bool X86DAGToDAGISel::SelectLEAAddr(SDValue Op, SDValue N, 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; |