[llvm] [AMDGPU] expand-fp: Change frem expansion criterion (PR #158285)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 16 07:38:12 PDT 2025
================
@@ -74,11 +74,63 @@ 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.
+ inline static const SmallVector<MVT, 3> ExpandableTypes{MVT::f16, MVT::f32,
+ MVT::f64};
+
+ /// Libcalls for frem instructions of the type at the corresponding
+ /// positions of ExpandableTypes.
+ inline static const SmallVector<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) {
+ auto *It = find(ExpandableTypes, VT.getSimpleVT());
+ if (It == ExpandableTypes.end())
+ return {};
+
+ return FremLibcalls[It - ExpandableTypes.begin()];
+ };
+
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 find(ExpandableTypes, VT.getSimpleVT());
+ }
+
+ /// Return true if the pass should expand a frem instruction of the
+ /// given \p Ty for the target represented by \p TLI. Expansion
+ /// should happen if the legalization for the scalar type uses a
+ /// non-existing libcall.
+ static bool shouldExpandFremType(const TargetLowering &TLI, EVT VT) {
+ TargetLowering::LegalizeAction LA = TLI.getOperationAction(ISD::FREM, VT);
----------------
arsenm wrote:
This probably mishandles vectors, but I doubt any target does anything other than scalarize this
https://github.com/llvm/llvm-project/pull/158285
More information about the llvm-commits
mailing list