- Detect "expr + expr * (-1)" and "expr * -1 + expr" as 0.
Details
- Reviewers
andydavis1 rriddle nicolasvasilache ftynse
Diff Detail
Event Timeline
mlir/lib/IR/AffineExpr.cpp | ||
---|---|---|
319 | It looks like these detection comments are reversed. I may be missing something, but it looks like this code block computes : expr * -1 + expr = 0. | |
320 | It looks like lBinOpExpr is the same as lBin? | |
330 | Why are these wrapped in scopes? | |
mlir/test/IR/affine-map.mlir | ||
187 | Can we not test the added detection directly: d0 + d0 * -1 and d0 * -1 + d0? |
mlir/lib/IR/AffineExpr.cpp | ||
---|---|---|
317 | This looks like it could separate concerns better.. |
mlir/lib/IR/AffineExpr.cpp | ||
---|---|---|
317 | We can actually generalize this to "check for constant multipliers if both are binary op expressions, add the constants, and the 0 times expr is already constructed as 0 if that's the case" - but that would make the logic and casing long and complex because expr * 1 is always expr by construction. So, you'd have to check for both expr and expr * const_not_1 on either side -- four different cases. I kept this simple for now but can extend it this way if you prefer. |
This has been subsumed by D76233.
mlir/lib/IR/AffineExpr.cpp | ||
---|---|---|
317 | I've now generalized to simplify c1 * expr + c2 * expr to (c1 + c2) * expr - the logic is more complex, but it's better than having two patches. | |
319 | You are right - the comments were switched. Anyway the commit is now generalized. | |
330 | There was no good reason - perceived readability. Anyway, this is outdated now. | |
mlir/test/IR/affine-map.mlir | ||
187 | d0 - d0 is internally d0 + d0 * -1. So we'll get the same thing. |
This looks like it could separate concerns better..
Shouldn't this be a single pattern that adds the constants and lets a 0 * expr canonicalization rewrite it to 0?