[Mlir-commits] [mlir] [mlir][Analysis][Presburger] Remove redundant local vars after composition (PR #211023)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Jul 21 08:55:59 PDT 2026
https://github.com/asraa updated https://github.com/llvm/llvm-project/pull/211023
>From 7c9dd6361f8459ae18c996396b1a4319dbe55333 Mon Sep 17 00:00:00 2001
From: Asra Ali <asraa at google.com>
Date: Tue, 21 Jul 2026 15:29:53 +0000
Subject: [PATCH] [mlir] integer relation: eliminate local vars when composing
Signed-off-by: Asra Ali <asraa at google.com>
---
.../Analysis/Presburger/IntegerRelation.cpp | 3 +++
.../Presburger/IntegerRelationTest.cpp | 19 +++++++++++++++++++
2 files changed, 22 insertions(+)
diff --git a/mlir/lib/Analysis/Presburger/IntegerRelation.cpp b/mlir/lib/Analysis/Presburger/IntegerRelation.cpp
index 93a725571078e..94a15dc3f8663 100644
--- a/mlir/lib/Analysis/Presburger/IntegerRelation.cpp
+++ b/mlir/lib/Analysis/Presburger/IntegerRelation.cpp
@@ -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) {
diff --git a/mlir/unittests/Analysis/Presburger/IntegerRelationTest.cpp b/mlir/unittests/Analysis/Presburger/IntegerRelationTest.cpp
index 90753d502d12c..c3da1c1556d26 100644
--- a/mlir/unittests/Analysis/Presburger/IntegerRelationTest.cpp
+++ b/mlir/unittests/Analysis/Presburger/IntegerRelationTest.cpp
@@ -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)
More information about the Mlir-commits
mailing list