[Mlir-commits] [mlir] [mlir][arith] Add ValueBoundsOpInterface external models for the arith operations DivUI and DivSI (PR #206514)
Hagai Lev Hacohen
llvmlistbot at llvm.org
Tue Jun 30 02:27:20 PDT 2026
================
@@ -62,6 +62,68 @@ struct AddIOpInterface
}
};
+struct DivUIOpInterface
+ : public ValueBoundsOpInterface::ExternalModel<DivUIOpInterface,
+ arith::DivUIOp> {
+ void populateBoundsForIndexValue(Operation *op, Value value,
+ ValueBoundsConstraintSet &cstr) const {
+ auto divOp = cast<arith::DivUIOp>(op);
+ assert(value == divOp.getResult() && "invalid value");
+
+ bool lhsNonNegative =
+ ValueBoundsConstraintSet::isProvablyNonNegative(divOp.getLhs(), cstr);
+ bool rhsPositive =
+ ValueBoundsConstraintSet::isProvablyPositive(divOp.getRhs(), cstr);
+ if (!lhsNonNegative || !rhsPositive)
+ return;
+
+ AffineExpr lhs = cstr.getExpr(divOp.getLhs());
+ AffineExpr rhs = cstr.getExpr(divOp.getRhs());
+ cstr.bound(value) >= 0;
+ cstr.bound(value) == lhs.floorDiv(rhs);
+ }
+};
+
+struct DivSIOpInterface
+ : public ValueBoundsOpInterface::ExternalModel<DivSIOpInterface,
+ arith::DivSIOp> {
+ void populateBoundsForIndexValue(Operation *op, Value value,
+ ValueBoundsConstraintSet &cstr) const {
+ auto divOp = cast<arith::DivSIOp>(op);
+ assert(value == divOp.getResult() && "invalid value");
+
+ Value lhsValue = divOp.getLhs();
+ Value rhsValue = divOp.getRhs();
+
+ bool lhsNonNegative =
+ ValueBoundsConstraintSet::isProvablyNonNegative(lhsValue, cstr);
+ bool lhsNonPositive =
+ ValueBoundsConstraintSet::isProvablyNonPositive(lhsValue, cstr);
+ bool rhsPositive =
+ ValueBoundsConstraintSet::isProvablyPositive(rhsValue, cstr);
+ bool rhsNegative =
+ ValueBoundsConstraintSet::isProvablyNegative(rhsValue, cstr);
+
+ AffineExpr lhs = cstr.getExpr(lhsValue);
+ AffineExpr rhs = cstr.getExpr(rhsValue);
+
+ cstr.bound(value) >= lhs.floorDiv(rhs);
----------------
HagaiLevHacohen wrote:
Yes, I added.
https://github.com/llvm/llvm-project/pull/206514
More information about the Mlir-commits
mailing list