Skip to content

Commit 2db982c

Browse files
committed
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
1 parent 650437f commit 2db982c

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,6 +2327,28 @@ X86TargetLowering::IsEligibleForTailCallOptimization(SDValue Callee,
23272327
if (isCalleeStructRet || isCallerStructRet)
23282328
return false;
23292329

2330+
// If the call result is in ST0 / ST1, it needs to be popped off the x87 stack.
2331+
// Therefore if it's not used by the call it is not safe to optimize this into
2332+
// a sibcall.
2333+
bool Unused = false;
2334+
for (unsigned i = 0, e = Ins.size(); i != e; ++i) {
2335+
if (!Ins[i].Used) {
2336+
Unused = true;
2337+
break;
2338+
}
2339+
}
2340+
if (Unused) {
2341+
SmallVector<CCValAssign, 16> RVLocs;
2342+
CCState CCInfo(CalleeCC, false, getTargetMachine(),
2343+
RVLocs, *DAG.getContext());
2344+
CCInfo.AnalyzeCallResult(Ins, RetCC_X86);
2345+
for (unsigned i = 0; i != RVLocs.size(); ++i) {
2346+
CCValAssign &VA = RVLocs[i];
2347+
if (VA.getLocReg() == X86::ST0 || VA.getLocReg() == X86::ST1)
2348+
return false;
2349+
}
2350+
}
2351+
23302352
// If the callee takes no arguments then go on to check the results of the
23312353
// call.
23322354
if (!Outs.empty()) {

0 commit comments

Comments
 (0)