[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:20:04 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:
I think what you wanted was to use `b.getAffineDimExpr(1)`. I can reproduce the error with that.
https://github.com/llvm/llvm-project/pull/119245
More information about the Mlir-commits
mailing list