Skip to content

Commit f31c962

Browse files
committed
[SDAG] Pass pointer type to libcall expansion for SoftenFloatRes stack slots
Solution for: #129264 (comment)
1 parent ab18cc2 commit f31c962

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4749,6 +4749,8 @@ class TargetLowering : public TargetLoweringBase {
47494749
// shouldExtendTypeInLibCall can get the original type before soften.
47504750
ArrayRef<EVT> OpsVTBeforeSoften;
47514751
EVT RetVTBeforeSoften;
4752+
ArrayRef<Type *> OpsTypeOverrides;
4753+
47524754
bool IsSigned : 1;
47534755
bool DoesNotReturn : 1;
47544756
bool IsReturnValueUsed : 1;
@@ -4786,6 +4788,13 @@ class TargetLowering : public TargetLoweringBase {
47864788
IsSoften = Value;
47874789
return *this;
47884790
}
4791+
4792+
/// Override the argument type for an operand. Leave the type as null to use
4793+
/// the type from the operand's node.
4794+
MakeLibCallOptions &setOpsTypeOverrides(ArrayRef<Type *> OpsTypes) {
4795+
OpsTypeOverrides = OpsTypes;
4796+
return *this;
4797+
}
47894798
};
47904799

47914800
/// This function lowers an abstract call to a function into an actual call.

llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -772,13 +772,16 @@ SDValue DAGTypeLegalizer::SoftenFloatRes_FFREXP(SDNode *N) {
772772

773773
SDLoc DL(N);
774774

775+
auto PointerTy = PointerType::getUnqual(*DAG.getContext());
775776
TargetLowering::MakeLibCallOptions CallOptions;
776777
SDValue Ops[2] = {GetSoftenedFloat(N->getOperand(0)), StackSlot};
777778
EVT OpsVT[2] = {VT0, StackSlot.getValueType()};
779+
Type* CallOpsTypeOverrides[2] = { nullptr, PointerTy };
778780

779781
// TODO: setTypeListBeforeSoften can't properly express multiple return types,
780782
// but we only really need to handle the 0th one for softening anyway.
781-
CallOptions.setTypeListBeforeSoften({OpsVT}, VT0, true);
783+
CallOptions.setTypeListBeforeSoften({OpsVT}, VT0, true)
784+
.setOpsTypeOverrides(CallOpsTypeOverrides);
782785

783786
auto [ReturnVal, Chain] = TLI.makeLibCall(DAG, LC, NVT0, Ops, CallOptions, DL,
784787
/*Chain=*/SDValue());
@@ -811,19 +814,23 @@ SDValue DAGTypeLegalizer::SoftenFloatRes_UnaryWithTwoFPResults(
811814
SmallVector<EVT, 3> OpsVT = {VT};
812815

813816
std::array<SDValue, 2> StackSlots;
817+
SmallVector<Type *, 3> CallOpsTypeOverrides = {nullptr};
818+
auto PointerTy = PointerType::getUnqual(*DAG.getContext());
814819
for (unsigned ResNum = 0; ResNum < N->getNumValues(); ++ResNum) {
815820
if (ResNum == CallRetResNo)
816821
continue;
817822
SDValue StackSlot = DAG.CreateStackTemporary(NVT);
818823
Ops.push_back(StackSlot);
819824
OpsVT.push_back(StackSlot.getValueType());
820825
StackSlots[ResNum] = StackSlot;
826+
CallOpsTypeOverrides.push_back(PointerTy);
821827
}
822828

823829
TargetLowering::MakeLibCallOptions CallOptions;
824830
// TODO: setTypeListBeforeSoften can't properly express multiple return types,
825831
// but since both returns have the same type it should be okay.
826-
CallOptions.setTypeListBeforeSoften({OpsVT}, VT, true);
832+
CallOptions.setTypeListBeforeSoften({OpsVT}, VT, true)
833+
.setOpsTypeOverrides(CallOpsTypeOverrides);
827834

828835
auto [ReturnVal, Chain] = TLI.makeLibCall(DAG, LC, NVT, Ops, CallOptions, DL,
829836
/*Chain=*/SDValue());

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,13 @@ TargetLowering::makeLibCall(SelectionDAG &DAG, RTLIB::Libcall LC, EVT RetVT,
157157
Args.reserve(Ops.size());
158158

159159
TargetLowering::ArgListEntry Entry;
160+
ArrayRef<Type *> OpsTypeOverrides = CallOptions.OpsTypeOverrides;
160161
for (unsigned i = 0; i < Ops.size(); ++i) {
161162
SDValue NewOp = Ops[i];
162163
Entry.Node = NewOp;
163-
Entry.Ty = Entry.Node.getValueType().getTypeForEVT(*DAG.getContext());
164+
Entry.Ty = i < OpsTypeOverrides.size() && OpsTypeOverrides[i]
165+
? OpsTypeOverrides[i]
166+
: Entry.Node.getValueType().getTypeForEVT(*DAG.getContext());
164167
Entry.IsSExt =
165168
shouldSignExtendTypeInLibCall(Entry.Ty, CallOptions.IsSigned);
166169
Entry.IsZExt = !Entry.IsSExt;

0 commit comments

Comments
 (0)