[Mlir-commits] [mlir] [mlir][arith] Mark `arith.remsi` and `arith.remui` as conditionally speculatable (PR #188263)
Matthias Springer
llvmlistbot at llvm.org
Tue Mar 24 08:02:32 PDT 2026
https://github.com/matthias-springer created https://github.com/llvm/llvm-project/pull/188263
Division by zero is undefined behavior, so these two ops cannot be pure. This commit marks them as conditionally speculatable, similar to `arith.divsi` and `arith.divui`.
>From d50d263097978e544b259b0c56984a17553ddbf8 Mon Sep 17 00:00:00 2001
From: Matthias Springer <me at m-sp.org>
Date: Tue, 24 Mar 2026 14:55:30 +0000
Subject: [PATCH] [mlir][arith] Mark `arith.remsi` and `arith.remui` as
conditionally speculatable
---
mlir/include/mlir/Dialect/Arith/IR/ArithOps.td | 18 ++++++++++++++++--
mlir/lib/Dialect/Arith/IR/ArithOps.cpp | 8 ++++++++
2 files changed, 24 insertions(+), 2 deletions(-)
diff --git a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
index 4b830c05bf585..50a09761f110d 100644
--- a/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
+++ b/mlir/include/mlir/Dialect/Arith/IR/ArithOps.td
@@ -678,7 +678,8 @@ def Arith_FloorDivSIOp : Arith_TotalIntBinaryOp<"floordivsi"> {
// RemUIOp
//===----------------------------------------------------------------------===//
-def Arith_RemUIOp : Arith_TotalIntBinaryOp<"remui"> {
+def Arith_RemUIOp : Arith_IntBinaryOp<"remui",
+ [ConditionallySpeculatable]> {
let summary = "unsigned integer division remainder operation";
let description = [{
Unsigned integer division remainder. Treats the leading bit as the most
@@ -701,6 +702,12 @@ def Arith_RemUIOp : Arith_TotalIntBinaryOp<"remui"> {
%x = arith.remui %y, %z : tensor<4x?xi8>
```
}];
+
+ let extraClassDeclaration = [{
+ /// Interface method for ConditionallySpeculatable.
+ Speculation::Speculatability getSpeculatability();
+ }];
+
let hasFolder = 1;
}
@@ -708,7 +715,8 @@ def Arith_RemUIOp : Arith_TotalIntBinaryOp<"remui"> {
// RemSIOp
//===----------------------------------------------------------------------===//
-def Arith_RemSIOp : Arith_TotalIntBinaryOp<"remsi"> {
+def Arith_RemSIOp : Arith_IntBinaryOp<"remsi",
+ [ConditionallySpeculatable]> {
let summary = "signed integer division remainder operation";
let description = [{
Signed integer division remainder. Treats the leading bit as sign, i.e. `6 %
@@ -731,6 +739,12 @@ def Arith_RemSIOp : Arith_TotalIntBinaryOp<"remsi"> {
%x = arith.remsi %y, %z : tensor<4x?xi8>
```
}];
+
+ let extraClassDeclaration = [{
+ /// Interface method for ConditionallySpeculatable.
+ Speculation::Speculatability getSpeculatability();
+ }];
+
let hasFolder = 1;
}
diff --git a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
index 155edc5070a9d..05f3e3986a024 100644
--- a/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
+++ b/mlir/lib/Dialect/Arith/IR/ArithOps.cpp
@@ -931,6 +931,10 @@ OpFoldResult arith::RemUIOp::fold(FoldAdaptor adaptor) {
return div0 ? Attribute() : result;
}
+Speculation::Speculatability arith::RemUIOp::getSpeculatability() {
+ return getDivUISpeculatability(getRhs());
+}
+
//===----------------------------------------------------------------------===//
// RemSIOp
//===----------------------------------------------------------------------===//
@@ -954,6 +958,10 @@ OpFoldResult arith::RemSIOp::fold(FoldAdaptor adaptor) {
return div0 ? Attribute() : result;
}
+Speculation::Speculatability arith::RemSIOp::getSpeculatability() {
+ return getDivSISpeculatability(getRhs());
+}
+
//===----------------------------------------------------------------------===//
// AndIOp
//===----------------------------------------------------------------------===//
More information about the Mlir-commits
mailing list