[Mlir-commits] [mlir] [mlir][arith] Add rounding mode support for 'remf' operation (PR #194126)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Sat Apr 25 02:06:45 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: artyo_Om (worthlane)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/194126.diff
4 Files Affected:
- (modified) mlir/include/mlir/Dialect/Arith/IR/ArithOps.td (+1-3)
- (modified) mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp (+8-3)
- (modified) mlir/test/Conversion/ArithToLLVM/arith-to-llvm.mlir (+11)
- (modified) mlir/test/Dialect/Arith/ops.mlir (+3-1)
``````````diff
diff --git a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
index ba9ccb6a01d66..375190a07b169 100644
--- a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
+++ b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
@@ -1273,13 +1273,11 @@ def Arith_DivFOp : Arith_FloatBinaryOpWithRoundingMode<"divf"> {
// RemFOp
//===----------------------------------------------------------------------===//
-def Arith_RemFOp : Arith_FloatBinaryOp<"remf"> {
+def Arith_RemFOp : Arith_FloatBinaryOpWithRoundingMode<"remf"> {
let summary = "floating point division remainder operation";
let description = [{
Returns the floating point division remainder.
The remainder has the same sign as the dividend (lhs operand).
-
- TODO: Add support for rounding modes.
}];
let hasFolder = 1;
}
diff --git a/mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp b/mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp
index 2624420cf5318..30f32b8e248f4 100644
--- a/mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp
+++ b/mlir/lib/Conversion/ArithToLLVM/ArithToLLVM.cpp
@@ -170,9 +170,13 @@ using NegFOpLowering =
/*FailOnUnsupportedFP=*/true>;
using OrIOpLowering = VectorConvertToLLVMPattern<arith::OrIOp, LLVM::OrOp>;
using RemFOpLowering =
- VectorConvertToLLVMPattern<arith::RemFOp, LLVM::FRemOp,
- arith::AttrConvertFastMathToLLVM,
- /*FailOnUnsupportedFP=*/true>;
+ ConstrainedVectorConvertToLLVMPattern<arith::RemFOp, LLVM::FRemOp,
+ /*HasRoundingMode=*/false,
+ arith::AttrConvertFastMathToLLVM,
+ /*FailOnUnsupportedFP=*/true>;
+using ConstrainedRemFOpLowering = ConstrainedVectorConvertToLLVMPattern<
+ arith::RemFOp, LLVM::ConstrainedFRemIntr, /*HasRoundingMode=*/true,
+ arith::AttrConverterConstrainedFPToLLVM, /*FailOnUnsupportedFP=*/true>;
using RemSIOpLowering =
VectorConvertToLLVMPattern<arith::RemSIOp, LLVM::SRemOp>;
using RemUIOpLowering =
@@ -760,6 +764,7 @@ void mlir::arith::populateArithToLLVMConversionPatterns(
NegFOpLowering,
OrIOpLowering,
RemFOpLowering,
+ ConstrainedRemFOpLowering,
RemSIOpLowering,
RemUIOpLowering,
SelectOpLowering,
diff --git a/mlir/test/Conversion/ArithToLLVM/arith-to-llvm.mlir b/mlir/test/Conversion/ArithToLLVM/arith-to-llvm.mlir
index df58d4ffcaf51..d1e10ea42d19f 100644
--- a/mlir/test/Conversion/ArithToLLVM/arith-to-llvm.mlir
+++ b/mlir/test/Conversion/ArithToLLVM/arith-to-llvm.mlir
@@ -451,6 +451,17 @@ func.func @experimental_constrained_divf(%arg0 : f64, %arg1 : f64) {
// -----
+// CHECK-LABEL: experimental_constrained_remf
+func.func @experimental_constrained_remf(%arg0 : f64, %arg1 : f64) {
+// CHECK-NEXT: = llvm.intr.experimental.constrained.frem %arg0, %arg1 tonearest ignore
+ %0 = arith.remf %arg0, %arg1 to_nearest_even : f64
+// CHECK-NEXT: = llvm.intr.experimental.constrained.frem %arg0, %arg1 tonearestaway ignore
+ %1 = arith.remf %arg0, %arg1 to_nearest_away : f64
+ return
+}
+
+// -----
+
// Verify that fastmath flags are stripped when lowering to constrained
// intrinsics (constrained FP and fastmath are contradictory).
// CHECK-LABEL: constrained_addf_with_fastmath
diff --git a/mlir/test/Dialect/Arith/ops.mlir b/mlir/test/Dialect/Arith/ops.mlir
index 059e35c384dac..21d9cd364f720 100644
--- a/mlir/test/Dialect/Arith/ops.mlir
+++ b/mlir/test/Dialect/Arith/ops.mlir
@@ -1276,8 +1276,10 @@ func.func @roundingmode(%arg0: f32, %arg1: f32) {
%2 = arith.mulf %arg0, %arg1 upward : f32
// CHECK: {{.*}} = arith.divf %arg0, %arg1 toward_zero : f32
%3 = arith.divf %arg0, %arg1 toward_zero : f32
+// CHECK: {{.*}} = arith.remf %arg0, %arg1 toward_zero : f32
+ %4 = arith.remf %arg0, %arg1 toward_zero : f32
// CHECK: {{.*}} = arith.addf %arg0, %arg1 to_nearest_even fastmath<fast> : f32
- %4 = arith.addf %arg0, %arg1 to_nearest_even fastmath<fast> : f32
+ %5 = arith.addf %arg0, %arg1 to_nearest_even fastmath<fast> : f32
return
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/194126
More information about the Mlir-commits
mailing list