Skip to content

Commit 95e705d

Browse files
committed
Merge 98561 from mainline.
Avoid sibcall optimization if either caller or callee is using sret semantics. llvm-svn: 99290
1 parent 18d41ba commit 95e705d

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,7 +1477,6 @@ X86TargetLowering::LowerFormalArguments(SDValue Chain,
14771477
DebugLoc dl,
14781478
SelectionDAG &DAG,
14791479
SmallVectorImpl<SDValue> &InVals) {
1480-
14811480
MachineFunction &MF = DAG.getMachineFunction();
14821481
X86MachineFunctionInfo *FuncInfo = MF.getInfo<X86MachineFunctionInfo>();
14831482

@@ -1779,7 +1778,8 @@ X86TargetLowering::LowerCall(SDValue Chain, SDValue Callee,
17791778

17801779
if (isTailCall) {
17811780
// 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(),
17831783
Outs, Ins, DAG);
17841784

17851785
// Sibcalls are automatically detected tailcalls which do not require
@@ -2297,6 +2297,8 @@ bool
22972297
X86TargetLowering::IsEligibleForTailCallOptimization(SDValue Callee,
22982298
CallingConv::ID CalleeCC,
22992299
bool isVarArg,
2300+
bool isCalleeStructRet,
2301+
bool isCallerStructRet,
23002302
const SmallVectorImpl<ISD::OutputArg> &Outs,
23012303
const SmallVectorImpl<ISD::InputArg> &Ins,
23022304
SelectionDAG& DAG) const {
@@ -2316,10 +2318,15 @@ X86TargetLowering::IsEligibleForTailCallOptimization(SDValue Callee,
23162318
// Look for obvious safe cases to perform tail call optimization that does not
23172319
// requite ABI changes. This is what gcc calls sibcall.
23182320

2319-
// Do not tail call optimize vararg calls for now.
2321+
// Do not sibcall optimize vararg calls for now.
23202322
if (isVarArg)
23212323
return false;
23222324

2325+
// Also avoid sibcall optimization if either caller or callee uses struct
2326+
// return semantics.
2327+
if (isCalleeStructRet || isCallerStructRet)
2328+
return false;
2329+
23232330
// If the callee takes no arguments then go on to check the results of the
23242331
// call.
23252332
if (!Outs.empty()) {

llvm/lib/Target/X86/X86ISelLowering.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,8 @@ namespace llvm {
637637
bool IsEligibleForTailCallOptimization(SDValue Callee,
638638
CallingConv::ID CalleeCC,
639639
bool isVarArg,
640+
bool isCalleeStructRet,
641+
bool isCallerStructRet,
640642
const SmallVectorImpl<ISD::OutputArg> &Outs,
641643
const SmallVectorImpl<ISD::InputArg> &Ins,
642644
SelectionDAG& DAG) const;

0 commit comments

Comments
 (0)