diff options
author | Evan Cheng <evan.cheng@apple.com> | 2008-08-24 19:19:55 +0000 |
---|---|---|
committer | Evan Cheng <evan.cheng@apple.com> | 2008-08-24 19:19:55 +0000 |
commit | 8fa17424f7cb37b7a1fcf752c49396324cb5031f (patch) | |
tree | f05574bfb69c420676d330330757f527506c87d3 | |
parent | 72e7d91591f438c3cd31a71f0996026c13d2e4c1 (diff) | |
download | bcm5719-llvm-8fa17424f7cb37b7a1fcf752c49396324cb5031f.tar.gz bcm5719-llvm-8fa17424f7cb37b7a1fcf752c49396324cb5031f.zip |
Move callseq_start above the call address load to allow load to be folded into the call node.
llvm-svn: 55292
-rw-r--r-- | llvm/lib/Target/X86/X86ISelLowering.cpp | 9 | ||||
-rw-r--r-- | llvm/test/CodeGen/X86/fold-call-2.ll | 10 |
2 files changed, 17 insertions, 2 deletions
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index 5d8cb1cd291..09a30db218a 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -1457,12 +1457,12 @@ EmitTailCallStoreRetAddr(SelectionDAG & DAG, MachineFunction &MF, SDValue X86TargetLowering::LowerCALL(SDValue Op, SelectionDAG &DAG) { MachineFunction &MF = DAG.getMachineFunction(); - SDValue Chain = Op.getOperand(0); + SDValue Chain = Op.getOperand(0); unsigned CC = cast<ConstantSDNode>(Op.getOperand(1))->getValue(); bool isVarArg = cast<ConstantSDNode>(Op.getOperand(2))->getValue() != 0; bool IsTailCall = cast<ConstantSDNode>(Op.getOperand(3))->getValue() != 0 && CC == CallingConv::Fast && PerformTailCallOpt; - SDValue Callee = Op.getOperand(4); + SDValue Callee = Op.getOperand(4); bool Is64Bit = Subtarget->is64Bit(); bool IsStructRet = CallIsStructReturn(Op); @@ -1499,6 +1499,11 @@ SDValue X86TargetLowering::LowerCALL(SDValue Op, SelectionDAG &DAG) { MF.getInfo<X86MachineFunctionInfo>()->setTCReturnAddrDelta(FPDiff); } + // If the address is a load, i.e. indirect function call, move callseq_start + // above the load. This makes it possible for the load to fold into the call. + if (Callee.Val == Chain.Val && ISD::isNormalLoad(Callee.Val) && + Chain.hasOneUse() && Callee.hasOneUse()) + Chain = Chain.getOperand(0); Chain = DAG.getCALLSEQ_START(Chain, DAG.getIntPtrConstant(NumBytes)); SDValue RetAddrFrIdx; diff --git a/llvm/test/CodeGen/X86/fold-call-2.ll b/llvm/test/CodeGen/X86/fold-call-2.ll new file mode 100644 index 00000000000..349f986830a --- /dev/null +++ b/llvm/test/CodeGen/X86/fold-call-2.ll @@ -0,0 +1,10 @@ +; RUN: llvm-as < %s | llc -mtriple=i386-apple-darwin | grep mov | count 1 + +@f = external global void ()* ; <void ()**> [#uses=1] + +define i32 @main() nounwind { +entry: + load void ()** @f, align 8 ; <void ()*>:0 [#uses=1] + tail call void %0( ) nounwind + ret i32 0 +} |