[llvm] [AMDGPU] expand-fp: Change frem expansion criterion (PR #158285)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 30 23:49:06 PDT 2025
================
@@ -74,11 +74,54 @@ class FRemExpander {
/// Constant 1 of type \p ExTy.
Value *One;
+ /// The frem argument/return types that can be expanded by this class.
+ // TODO The expansion could work for other floating point types
+ // as well, but this would require additional testing.
+ static constexpr std::array<MVT, 3> ExpandableTypes{MVT::f16, MVT::f32,
+ MVT::f64};
+
+ /// Libcalls for frem instructions of the type at the corresponding
+ /// positions of ExpandableTypes.
+ static constexpr std::array<RTLIB::Libcall, 3> FremLibcalls{
+ RTLIB::REM_F32, RTLIB::REM_F32, RTLIB::REM_F64};
+
+ /// Return the Libcall for frem instructions of expandable type \p VT or
+ /// std::nullopt if \p VT is not expandable.
+ static std::optional<RTLIB::Libcall> getFremLibcallForType(EVT VT) {
+ MVT V = VT.getSimpleVT();
+ for (unsigned I = 0; I < ExpandableTypes.size(); I++)
+ if (ExpandableTypes[I] == V)
+ return FremLibcalls[I];
+
+ return {};
+ };
+
public:
static bool canExpandType(Type *Ty) {
- // TODO The expansion should work for other floating point types
- // as well, but this would require additional testing.
- return Ty->isIEEELikeFPTy() && !Ty->isBFloatTy() && !Ty->isFP128Ty();
+ EVT VT = EVT::getEVT(Ty);
+ assert(VT.isSimple() && "Can expand only simple types");
+
+ return is_contained(ExpandableTypes, VT.getSimpleVT());
+ }
+
+ static bool shouldExpandFremType(const TargetLowering &TLI, EVT VT) {
+ assert(!VT.isVector() && "Cannot handle vector type; must scalarize first");
+ return (TLI.getOperationAction(ISD::FREM, VT) ==
+ TargetLowering::LegalizeAction::Expand);
----------------
arsenm wrote:
```suggestion
return TLI.getOperationAction(ISD::FREM, VT) ==
TargetLowering::LegalizeAction::Expand;
```
https://github.com/llvm/llvm-project/pull/158285
More information about the llvm-commits
mailing list