[MLIR][Presburger] MultiAffineFunction:eliminateRedundantLocalId: fix bug where local...
authorArjun P <arjunpitchanathan@gmail.com>
Thu, 31 Mar 2022 11:34:33 +0000 (12:34 +0100)
committerArjun P <arjunpitchanathan@gmail.com>
Thu, 31 Mar 2022 14:11:55 +0000 (15:11 +0100)
Previously, when updating the outputs matrix, the local offset was not being considered.

Reviewed By: Groverkss

Differential Revision: https://reviews.llvm.org/D122812

mlir/lib/Analysis/Presburger/PWMAFunction.cpp
mlir/unittests/Analysis/Presburger/PWMAFunctionTest.cpp

index 42b2511..d00bc2d 100644 (file)
@@ -110,7 +110,8 @@ void MultiAffineFunction::removeIdRange(IdKind kind, unsigned idStart,
 
 void MultiAffineFunction::eliminateRedundantLocalId(unsigned posA,
                                                     unsigned posB) {
-  output.addToColumn(posB, posA, /*scale=*/1);
+  unsigned localOffset = getIdKindOffset(IdKind::Local);
+  output.addToColumn(localOffset + posB, localOffset + posA, /*scale=*/1);
   IntegerPolyhedron::eliminateRedundantLocalId(posA, posB);
 }
 
index 79139de..27d0252 100644 (file)
@@ -157,19 +157,35 @@ TEST(PWMAFunction, valueAt) {
 }
 
 TEST(PWMAFunction, removeIdRangeRegressionTest) {
-  PWMAFunction pwafA = parsePWMAF(
+  PWMAFunction pwmafA = parsePWMAF(
       /*numInputs=*/2, /*numOutputs=*/1,
       {
           {"(x, y) : (x == 0, y == 0, x - 2*(x floordiv 2) == 0, y - 2*(y "
            "floordiv 2) == 0)",
            {{0, 0, 0, 0, 0}}} // (0, 0)
       });
-  PWMAFunction pwafB = parsePWMAF(
+  PWMAFunction pwmafB = parsePWMAF(
       /*numInputs=*/2, /*numOutputs=*/1,
       {
           {"(x, y) : (x - 11*y == 0, 11*x - y == 0, x - 2*(x floordiv 2) == 0, "
            "y - 2*(y floordiv 2) == 0)",
            {{0, 0, 0, 0, 0}}} // (0, 0)
       });
-  EXPECT_TRUE(pwafA.isEqual(pwafB));
+  EXPECT_TRUE(pwmafA.isEqual(pwmafB));
+}
+
+TEST(PWMAFunction, eliminateRedundantLocalIdRegressionTest) {
+  PWMAFunction pwmafA = parsePWMAF(
+      /*numInputs=*/2, /*numOutputs=*/1,
+      {
+          {"(x, y) : (x - 2*(x floordiv 2) == 0, x - 2*y == 0)",
+           {{0, 1, 0, 0}}} // (0, 0)
+      });
+  PWMAFunction pwmafB = parsePWMAF(
+      /*numInputs=*/2, /*numOutputs=*/1,
+      {
+          {"(x, y) : (x - 2*(x floordiv 2) == 0, x - 2*y == 0)",
+           {{1, -1, 0, 0}}} // (0, 0)
+      });
+  EXPECT_TRUE(pwmafA.isEqual(pwmafB));
 }