summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTanya Lattner <tonic@nondot.org>2010-03-23 17:16:35 +0000
committerTanya Lattner <tonic@nondot.org>2010-03-23 17:16:35 +0000
commit2db982c41f6dd7ed4c01163b6ac9406911e7c7f4 (patch)
treeb4f0f2e59d8fa968158aff50ff58d66570f756f3
parent650437f2ef17f6a36682545ff2f14236ef732c29 (diff)
downloadllvm-2db982c41f6dd7ed4c01163b6ac9406911e7c7f4.tar.gz
Merge 99032 from mainline.
If call result is in ST0 and it is not being passed to the caller's caller, then it is not safe to optimize the call into a sibcall since the call result has to be popped off the x87 stack. llvm-svn: 99293
-rw-r--r--llvm/lib/Target/X86/X86ISelLowering.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp
index 9c40a7007fe7..ae06ee44e628 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -2327,6 +2327,28 @@ X86TargetLowering::IsEligibleForTailCallOptimization(SDValue Callee,
if (isCalleeStructRet || isCallerStructRet)
return false;
+ // If the call result is in ST0 / ST1, it needs to be popped off the x87 stack.
+ // Therefore if it's not used by the call it is not safe to optimize this into
+ // a sibcall.
+ bool Unused = false;
+ for (unsigned i = 0, e = Ins.size(); i != e; ++i) {
+ if (!Ins[i].Used) {
+ Unused = true;
+ break;
+ }
+ }
+ if (Unused) {
+ SmallVector<CCValAssign, 16> RVLocs;
+ CCState CCInfo(CalleeCC, false, getTargetMachine(),
+ RVLocs, *DAG.getContext());
+ CCInfo.AnalyzeCallResult(Ins, RetCC_X86);
+ for (unsigned i = 0; i != RVLocs.size(); ++i) {
+ CCValAssign &VA = RVLocs[i];
+ if (VA.getLocReg() == X86::ST0 || VA.getLocReg() == X86::ST1)
+ return false;
+ }
+ }
+
// If the callee takes no arguments then go on to check the results of the
// call.
if (!Outs.empty()) {