[all-commits] [llvm/llvm-project] 39cf65: [mlir][affine] Implement ValueBoundsOpInterface fo...

Dhairyashil R G via All-commits all-commits at lists.llvm.org
Fri Aug 7 01:41:53 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 39cf655fdaafcff6e2fc145bd9a286f1d748dc3b
      https://github.com/llvm/llvm-project/commit/39cf655fdaafcff6e2fc145bd9a286f1d748dc3b
  Author: Dhairyashil R G <dhairyashil25 at gmail.com>
  Date:   2026-08-07 (Fri, 07 Aug 2026)

  Changed paths:
    M mlir/lib/Dialect/Affine/IR/ValueBoundsOpInterfaceImpl.cpp
    M mlir/test/Dialect/Affine/value-bounds-op-interface-impl.mlir

  Log Message:
  -----------
  [mlir][affine] Implement ValueBoundsOpInterface for affine.for (#214614)

`scf.for` has provided induction variable bounds through
`ValueBoundsOpInterface` for a long time, but `affine.for` has no model
at all. `ValueBoundsConstraintSet` therefore cannot derive any bound for
an affine induction variable, not even `iv >= lowerBound`. Queries just
return "unknown", which is easy to miss because it looks the same as a
bound that genuinely cannot be proven.

Add a model for the induction variable. The lower bound of an
`affine.for` is the maximum over the results of its lower bound map and
the upper bound is the minimum over the results of its upper bound map,
so the induction variable is constrained by every individual result.
This follows how `AffineMinOpInterface` and `AffineMaxOpInterface` in
the same file align their maps with the constraint set; the shared logic
is factored into `alignBoundExpr`.

When both maps have exactly one result the step is taken into account as
well, following `scf::ForOpInterface`: the induction variable is always
a multiple of `step` away from the lower bound, so it never exceeds `lb
+ (tripCount - 1) * step`. That is tighter than `ub - 1` whenever the
trip count is not a multiple of the step, for `affine.for %i = 0 to 300
step 128` the induction variable only ever takes {0, 128, 256}, so the
bound is 256 rather than 299. As in `scf::ForOpInterface` this does not
replace the `iv < ub` constraint, since constraints multiplying two
constraint set dimensions aren't supported. The step is not applied when
either map has multiple results (`max`/`min` bounds), since no single
result can drive the arithmetic.

No bounds are inferred for `iter_args`.

Beyond the lit tests, the bound arithmetic was checked against an oracle
sweep: 6268 loops over an exhaustive `(lb, ub, step)` grid plus 4000
random cases, with the true induction variable range computed by
simulating each loop in Python rather than by asking the compiler.
Across 12536 queries there were 0 unsound bounds and 0 loose ones —
every bound is exactly `max(iv)` and `min(iv)`, so the model captures
every provable case rather than a conservative subset. Two controls:
reverting the change makes all 12536 queries unprovable, and mutating
the step arithmetic to be one step too tight makes the sweep report 5643
unsound bounds with counterexamples. The harness discriminates in both
directions.

No existing test needed updating: on its own this causes no `in_bounds`
folding in the vector dialect, because `isInBounds` still bails on any
non-constant index. Using these bounds there is a follow-up I'd like to
send once this lands.

Assisted-by: Claude



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list