[Mlir-commits] [mlir] [mlir][IR] Fix bug in AffineExpr simplifier `lhs % rhs` where `lhs = lhs floordiv rhs` (PR #119245)
Kunwar Grover
llvmlistbot at llvm.org
Wed Dec 11 16:16:12 PST 2024
================
@@ -129,3 +129,24 @@ TEST(AffineExprTest, d0PlusD0FloorDivNeg2) {
auto sum = d0 + d0.floorDiv(-2) * 2;
ASSERT_EQ(toString(sum), "d0 + (d0 floordiv -2) * 2");
}
+
+TEST(AffineExprTEst, simpleAffineExprFlattenerRegression) {
+
+ // Regression test for a bug where mod simplification was not handled
+ // properly when `lhs % rhs` was happened to have the property that `lhs
+ // floordiv rhs = lhs`.
+ MLIRContext ctx;
+ OpBuilder b(&ctx);
+
+ auto d0 = b.getAffineDimExpr(0);
+ auto d1 = b.getAffineDimExpr(1);
+
+ // Manually replace variables by constants to avoid constant folding.
+ AffineExpr expr = (d0 - (d1 + 2)).floorDiv(8) % 8;
+ expr = expr.replaceDims(
+ {b.getAffineConstantExpr(1), b.getAffineConstantExpr(1)});
----------------
Groverkss wrote:
This will just simplify the AffineExpr to a constant. The later call to simplifyAffineExpr will simply not materialize. I ran this test with your patch and without your patch and the printing is same:
```
Original:
((d0 - (d1 + 2)) floordiv 8) mod 8
Replacement:
7
Simplified:
7
```
Please add a symbolic test where the bug can actually be seen.
https://github.com/llvm/llvm-project/pull/119245
More information about the Mlir-commits
mailing list