@@ -1477,7 +1477,6 @@ X86TargetLowering::LowerFormalArguments(SDValue Chain,
1477
1477
DebugLoc dl,
1478
1478
SelectionDAG &DAG,
1479
1479
SmallVectorImpl<SDValue> &InVals) {
1480
-
1481
1480
MachineFunction &MF = DAG.getMachineFunction ();
1482
1481
X86MachineFunctionInfo *FuncInfo = MF.getInfo <X86MachineFunctionInfo>();
1483
1482
@@ -1779,7 +1778,8 @@ X86TargetLowering::LowerCall(SDValue Chain, SDValue Callee,
1779
1778
1780
1779
if (isTailCall) {
1781
1780
// Check if it's really possible to do a tail call.
1782
- isTailCall = IsEligibleForTailCallOptimization (Callee, CallConv, isVarArg,
1781
+ isTailCall = IsEligibleForTailCallOptimization (Callee, CallConv,
1782
+ isVarArg, IsStructRet, MF.getFunction ()->hasStructRetAttr (),
1783
1783
Outs, Ins, DAG);
1784
1784
1785
1785
// Sibcalls are automatically detected tailcalls which do not require
@@ -2297,6 +2297,8 @@ bool
2297
2297
X86TargetLowering::IsEligibleForTailCallOptimization (SDValue Callee,
2298
2298
CallingConv::ID CalleeCC,
2299
2299
bool isVarArg,
2300
+ bool isCalleeStructRet,
2301
+ bool isCallerStructRet,
2300
2302
const SmallVectorImpl<ISD::OutputArg> &Outs,
2301
2303
const SmallVectorImpl<ISD::InputArg> &Ins,
2302
2304
SelectionDAG& DAG) const {
@@ -2316,10 +2318,15 @@ X86TargetLowering::IsEligibleForTailCallOptimization(SDValue Callee,
2316
2318
// Look for obvious safe cases to perform tail call optimization that does not
2317
2319
// requite ABI changes. This is what gcc calls sibcall.
2318
2320
2319
- // Do not tail call optimize vararg calls for now.
2321
+ // Do not sibcall optimize vararg calls for now.
2320
2322
if (isVarArg)
2321
2323
return false ;
2322
2324
2325
+ // Also avoid sibcall optimization if either caller or callee uses struct
2326
+ // return semantics.
2327
+ if (isCalleeStructRet || isCallerStructRet)
2328
+ return false ;
2329
+
2323
2330
// If the callee takes no arguments then go on to check the results of the
2324
2331
// call.
2325
2332
if (!Outs.empty ()) {
0 commit comments