[mlir][Analysis][Presburger] Remove redundant local vars after composition (#211023)

Call `removeRedundantLocalVars()` at the end of
`IntegerRelation::compose` to simplify existential constraints generated
when projecting out intermediate dimensions.

Removing redundant local vars also happens in
`IntegerRelation::mergeAndCompose` and `FlatAffineRelation::compose`.

When composing A->B with B->C, intermediate vars B are converted to
local existential variables. When performing multiple compositions, this
causes bloat of existential variables that impact later performance,
bounds checks, and emptiness checks.

Signed-off-by: Asra Ali <asraa@google.com>
This commit is contained in:
asraa 2026-07-21 11:13:57 -05:00 committed by GitHub
parent b59caeffc2
commit 19822360d8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 0 deletions

View file

@ -2573,6 +2573,9 @@ void IntegerRelation::compose(const IntegerRelation &rel) {
// Project out B in R1.
convertVarKind(VarKind::Range, 0, numBVars, VarKind::Local);
// Eliminate local variables
removeRedundantLocalVars();
}
void IntegerRelation::applyDomain(const IntegerRelation &rel) {

View file

@ -119,6 +119,25 @@ TEST(IntegerRelationTest, applyDomainAndRange) {
}
}
TEST(IntegerRelationTest, composeRemoveRedundantLocalVars) {
// map x to y = x + 10.
IntegerRelation map1 =
parseRelationFromSet("(x, y) : (y - x - 10 == 0)", /*numDomain=*/1);
// map y to z = y + 20.
IntegerRelation map2 =
parseRelationFromSet("(y, z) : (z - y - 20 == 0)", /*numDomain=*/1);
// composing projects out y (converting it to a local variable)
map1.compose(map2);
// y is fully determined by x so should be eliminated after composition
EXPECT_EQ(map1.getNumLocalVars(), 0u);
IntegerRelation expectedMap =
parseRelationFromSet("(x, z) : (z - x - 30 == 0)", /*numDomain=*/1);
EXPECT_TRUE(map1.isEqual(expectedMap));
}
TEST(IntegerRelationTest, symbolicLexmin) {
SymbolicLexOpt lexmin =
parseRelationFromSet("(a, x)[b] : (x - a >= 0, x - b >= 0)", 1)