[Mlir-commits] [mlir] [mlir][IR] Fix bug in AffineExpr simplifier `lhs % rhs` where `lhs = lhs floordiv rhs` (PR #119245)
Christopher Bate
llvmlistbot at llvm.org
Thu Dec 12 09:15:36 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)});
----------------
christopherbate wrote:
Thanks, yeah I put in the test wrong, not sure what I was thinking there. Fixed it so that it fails before the change and passes after.
https://github.com/llvm/llvm-project/pull/119245
More information about the Mlir-commits
mailing list