-
Notifications
You must be signed in to change notification settings - Fork 14k
[SDAG] Pass pointer type to libcall expansion for SoftenFloatRes stack slots #130647
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-llvm-selectiondag Author: Benjamin Maxwell (MacDue) ChangesSolution for: #129264 (comment) Full diff: https://github.com/llvm/llvm-project/pull/130647.diff 3 Files Affected:
diff --git a/llvm/include/llvm/CodeGen/TargetLowering.h b/llvm/include/llvm/CodeGen/TargetLowering.h
index 2089d47e9cbc8..051848b4acc3a 100644
--- a/llvm/include/llvm/CodeGen/TargetLowering.h
+++ b/llvm/include/llvm/CodeGen/TargetLowering.h
@@ -4749,6 +4749,8 @@ class TargetLowering : public TargetLoweringBase {
// shouldExtendTypeInLibCall can get the original type before soften.
ArrayRef<EVT> OpsVTBeforeSoften;
EVT RetVTBeforeSoften;
+ ArrayRef<Type *> OpsTypeOverrides;
+
bool IsSigned : 1;
bool DoesNotReturn : 1;
bool IsReturnValueUsed : 1;
@@ -4786,6 +4788,13 @@ class TargetLowering : public TargetLoweringBase {
IsSoften = Value;
return *this;
}
+
+ /// Override the argument type for an operand. Leave the type as null to use
+ /// the type from the operand's node.
+ MakeLibCallOptions &setOpsTypeOverrides(ArrayRef<Type *> OpsTypes) {
+ OpsTypeOverrides = OpsTypes;
+ return *this;
+ }
};
/// This function lowers an abstract call to a function into an actual call.
diff --git a/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp b/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
index c2107a73301bc..51de89ac6f29b 100644
--- a/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/LegalizeFloatTypes.cpp
@@ -772,13 +772,16 @@ SDValue DAGTypeLegalizer::SoftenFloatRes_FFREXP(SDNode *N) {
SDLoc DL(N);
+ auto PointerTy = PointerType::getUnqual(*DAG.getContext());
TargetLowering::MakeLibCallOptions CallOptions;
SDValue Ops[2] = {GetSoftenedFloat(N->getOperand(0)), StackSlot};
EVT OpsVT[2] = {VT0, StackSlot.getValueType()};
+ Type* CallOpsTypeOverrides[2] = { nullptr, PointerTy };
// TODO: setTypeListBeforeSoften can't properly express multiple return types,
// but we only really need to handle the 0th one for softening anyway.
- CallOptions.setTypeListBeforeSoften({OpsVT}, VT0, true);
+ CallOptions.setTypeListBeforeSoften({OpsVT}, VT0, true)
+ .setOpsTypeOverrides(CallOpsTypeOverrides);
auto [ReturnVal, Chain] = TLI.makeLibCall(DAG, LC, NVT0, Ops, CallOptions, DL,
/*Chain=*/SDValue());
@@ -811,6 +814,8 @@ SDValue DAGTypeLegalizer::SoftenFloatRes_UnaryWithTwoFPResults(
SmallVector<EVT, 3> OpsVT = {VT};
std::array<SDValue, 2> StackSlots;
+ SmallVector<Type *, 3> CallOpsTypeOverrides = {nullptr};
+ auto PointerTy = PointerType::getUnqual(*DAG.getContext());
for (unsigned ResNum = 0; ResNum < N->getNumValues(); ++ResNum) {
if (ResNum == CallRetResNo)
continue;
@@ -818,12 +823,14 @@ SDValue DAGTypeLegalizer::SoftenFloatRes_UnaryWithTwoFPResults(
Ops.push_back(StackSlot);
OpsVT.push_back(StackSlot.getValueType());
StackSlots[ResNum] = StackSlot;
+ CallOpsTypeOverrides.push_back(PointerTy);
}
TargetLowering::MakeLibCallOptions CallOptions;
// TODO: setTypeListBeforeSoften can't properly express multiple return types,
// but since both returns have the same type it should be okay.
- CallOptions.setTypeListBeforeSoften({OpsVT}, VT, true);
+ CallOptions.setTypeListBeforeSoften({OpsVT}, VT, true)
+ .setOpsTypeOverrides(CallOpsTypeOverrides);
auto [ReturnVal, Chain] = TLI.makeLibCall(DAG, LC, NVT, Ops, CallOptions, DL,
/*Chain=*/SDValue());
diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
index bd72718c49031..f1649a3903fac 100644
--- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp
@@ -157,10 +157,13 @@ TargetLowering::makeLibCall(SelectionDAG &DAG, RTLIB::Libcall LC, EVT RetVT,
Args.reserve(Ops.size());
TargetLowering::ArgListEntry Entry;
+ ArrayRef<Type *> OpsTypeOverrides = CallOptions.OpsTypeOverrides;
for (unsigned i = 0; i < Ops.size(); ++i) {
SDValue NewOp = Ops[i];
Entry.Node = NewOp;
- Entry.Ty = Entry.Node.getValueType().getTypeForEVT(*DAG.getContext());
+ Entry.Ty = i < OpsTypeOverrides.size() && OpsTypeOverrides[i]
+ ? OpsTypeOverrides[i]
+ : Entry.Node.getValueType().getTypeForEVT(*DAG.getContext());
Entry.IsSExt =
shouldSignExtendTypeInLibCall(Entry.Ty, CallOptions.IsSigned);
Entry.IsZExt = !Entry.IsSExt;
|
No tests right now as this is not needed for any upstream targets (as far as I know). |
✅ With the latest revision this PR passed the C/C++ code formatter. |
…k slots Solution for: llvm#129264 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…k slots (llvm#130647) Solution for: llvm#129264 (comment)
Solution for: #129264 (comment)