Skip to content

Conversation

@Max191
Copy link
Contributor

@Max191 Max191 commented Nov 21, 2025

Adds support for analyzing the induction variables of loop-like ops in the IntegerDivisibilityAnalysis. This just uses the lower bound and step divisibilities to compute the IV divisibilities based on the simple lb + i * step expression.

Implements divisibility inference for affine.apply, affine.min, and
affine.max operations through AffineExprDivisibilityFinder visitor.
The visitor recursively computes divisibility for affine expressions:
- Multiplication: product of operand divisibilities
- Addition/Subtraction: GCD (union) of operand divisibilities
- Division (floor/ceil): quotient when evenly divisible, else 1
- Modulo: falls back to minimum divisibility (1,1)
- Min/Max: GCD of all branch divisibilities

Adds TestIntegerDivisibilityAnalysis pass to more directly test
divisibility analysis without relying on IR optimizations. The pass
probes values with iree_unregistered.test_int_divisibility ops and
annotates them with computed divisibility attributes.

Also updates arith::DivUIOp divisibility calculation to fallback
to minimum divisibility when there is a remainder division,
because we can't infer the divisibility when there is a remainder.

Signed-off-by: Max Dawkins <[email protected]>
@Max191
Copy link
Contributor Author

Max191 commented Nov 21, 2025

Based on #22723 to pull in the testing pass (otherwise the PRs are independent), so just review the last commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant