Skip to content

Commit 590a2b0

Browse files
authored
Revert "ARM: Remove unnecessary manual ABI lowering for sincos_stret (#166040)" (#166262)
This reverts commit a522ae3. The ABI handling doesn't account for matching the C ABI, only implicit sret.
1 parent d4c41b7 commit 590a2b0

File tree

1 file changed

+37
-2
lines changed

1 file changed

+37
-2
lines changed

llvm/lib/Target/ARM/ARMISelLowering.cpp

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9869,12 +9869,32 @@ SDValue ARMTargetLowering::LowerFSINCOS(SDValue Op, SelectionDAG &DAG) const {
98699869
assert(Subtarget->isTargetDarwin());
98709870

98719871
Type *ArgTy = ArgVT.getTypeForEVT(*DAG.getContext());
9872+
auto PtrVT = getPointerTy(DAG.getDataLayout());
9873+
9874+
MachineFrameInfo &MFI = DAG.getMachineFunction().getFrameInfo();
98729875

98739876
// Pair of floats / doubles used to pass the result.
98749877
Type *RetTy = StructType::get(ArgTy, ArgTy);
98759878
auto &DL = DAG.getDataLayout();
98769879

98779880
ArgListTy Args;
9881+
bool ShouldUseSRet = getTM().isAPCS_ABI();
9882+
SDValue SRet;
9883+
if (ShouldUseSRet) {
9884+
// Create stack object for sret.
9885+
const uint64_t ByteSize = DL.getTypeAllocSize(RetTy);
9886+
const Align StackAlign = DL.getPrefTypeAlign(RetTy);
9887+
int FrameIdx = MFI.CreateStackObject(ByteSize, StackAlign, false);
9888+
SRet = DAG.getFrameIndex(FrameIdx, getPointerTy(DL));
9889+
9890+
ArgListEntry Entry(SRet, PointerType::getUnqual(RetTy->getContext()));
9891+
Entry.IsSExt = false;
9892+
Entry.IsZExt = false;
9893+
Entry.IsSRet = true;
9894+
Args.push_back(Entry);
9895+
RetTy = Type::getVoidTy(*DAG.getContext());
9896+
}
9897+
98789898
Args.emplace_back(Arg, ArgTy);
98799899

98809900
StringRef LibcallName = getLibcallImplName(SincosStret);
@@ -9884,10 +9904,25 @@ SDValue ARMTargetLowering::LowerFSINCOS(SDValue Op, SelectionDAG &DAG) const {
98849904
TargetLowering::CallLoweringInfo CLI(DAG);
98859905
CLI.setDebugLoc(dl)
98869906
.setChain(DAG.getEntryNode())
9887-
.setCallee(CC, RetTy, Callee, std::move(Args));
9907+
.setCallee(CC, RetTy, Callee, std::move(Args))
9908+
.setDiscardResult(ShouldUseSRet);
98889909
std::pair<SDValue, SDValue> CallResult = LowerCallTo(CLI);
98899910

9890-
return CallResult.first;
9911+
if (!ShouldUseSRet)
9912+
return CallResult.first;
9913+
9914+
SDValue LoadSin =
9915+
DAG.getLoad(ArgVT, dl, CallResult.second, SRet, MachinePointerInfo());
9916+
9917+
// Address of cos field.
9918+
SDValue Add = DAG.getNode(ISD::ADD, dl, PtrVT, SRet,
9919+
DAG.getIntPtrConstant(ArgVT.getStoreSize(), dl));
9920+
SDValue LoadCos =
9921+
DAG.getLoad(ArgVT, dl, LoadSin.getValue(1), Add, MachinePointerInfo());
9922+
9923+
SDVTList Tys = DAG.getVTList(ArgVT, ArgVT);
9924+
return DAG.getNode(ISD::MERGE_VALUES, dl, Tys,
9925+
LoadSin.getValue(0), LoadCos.getValue(0));
98919926
}
98929927

98939928
SDValue ARMTargetLowering::LowerWindowsDIVLibCall(SDValue Op, SelectionDAG &DAG,

0 commit comments

Comments
 (0)