[Mlir-commits] [mlir] [mlir][arith] Implement ValueBoundsOpInterface for IndexCastUI and ExtSI ops (PR #204476)

Matthias Springer llvmlistbot at llvm.org
Wed Jun 24 04:34:37 PDT 2026


================
@@ -17,6 +17,43 @@ namespace mlir {
 namespace arith {
 namespace {
 
+struct ConstantOpInterface
+    : public ValueBoundsOpInterface::ExternalModel<ConstantOpInterface,
+                                                   ConstantOp> {
+  void populateBoundsForIndexValue(Operation *op, Value value,
+                                   ValueBoundsConstraintSet &cstr) const {
+    auto constantOp = cast<ConstantOp>(op);
+    assert(value == constantOp.getResult() && "invalid value");
+
+    if (auto attr = llvm::dyn_cast<IntegerAttr>(constantOp.getValue()))
+      cstr.bound(value) == attr.getInt();
+  }
+};
+
+struct IndexCastUIOpInterface
+    : public ValueBoundsOpInterface::ExternalModel<IndexCastUIOpInterface,
+                                                   IndexCastUIOp> {
+  void populateBoundsForIndexValue(Operation *op, Value value,
+                                   ValueBoundsConstraintSet &cstr) const {
+    auto indexCastOp = cast<IndexCastUIOp>(op);
+    assert(value == indexCastOp.getOut() && "invalid value");
+    cstr.bound(value) >= 0;
----------------
matthias-springer wrote:

Is this correct?
```mlir
%0 = arith.constant -1 : index
%1 = arith.index_castui %0 : index to i64
```
Assuming that `index` has 64-bits on your platform, `%1` is `-1`.


https://github.com/llvm/llvm-project/pull/204476


More information about the Mlir-commits mailing list