[WIP] A collection of affine expressions utils#671
[WIP] A collection of affine expressions utils#671Hardcode84 wants to merge 24 commits intoiree-org:mainfrom
Conversation
| Example: | ||
| %0 = affine.apply affine_map<(d0)[s0] -> (d0 + s0)>(%x)[%y] | ||
| %1 = arith.addi %0, %c4 : index | ||
|
|
||
| Transforms to: | ||
| %1 = affine.apply affine_map<(d0)[s0, s1] -> (d0 + s0 + s1)>(%x)[%y, %c4] |
There was a problem hiding this comment.
I think we have the operand folding upstream, maybe we can also add a canonicalization for result folding (can't use fold because we can't have arith depend on affine).
| This pass reorders the operands of affine.apply operations to improve | ||
| hoistability and enable better loop-invariant code motion. Operands | ||
| that are more likely to be loop-invariant are moved to symbol positions. |
There was a problem hiding this comment.
We have canonicalizeAffineApplyAndOperands (or something like that) upstream that should be moving operands to symbols when applicable. There is extra semantics that says symbols should not be (affine) loop induction variables, so we can't just arbitrarily make things symbols.
| The pass works in two phases: | ||
| 1. Collects all affine.apply operations and builds hash statistics for | ||
| all sub-expressions encountered. | ||
| 2. For each commutative operation, tries all permutations and selects | ||
| the ordering that maximizes hash hits (sum of occurrence counts). |
There was a problem hiding this comment.
Would it be simpler to just convert affine to arith, run CSE, and then recover the affine form back by "raising"?
There was a problem hiding this comment.
It's not just doing the CSE, it's checking all permutations of commutative ops to match it better with any previous exprs encountered. Which is still doable on arith level, of course.
60c3c3c to
13e2f8f
Compare
Signed-off-by: Ivan Butygin <ivan.butygin@gmail.com>
Signed-off-by: Ivan Butygin <ivan.butygin@gmail.com>
Signed-off-by: Ivan Butygin <ivan.butygin@gmail.com>
Signed-off-by: Ivan Butygin <ivan.butygin@gmail.com>
Signed-off-by: Ivan Butygin <ivan.butygin@gmail.com>
Signed-off-by: Ivan Butygin <ivan.butygin@gmail.com>
Signed-off-by: Ivan Butygin <ivan.butygin@gmail.com>
Signed-off-by: Ivan Butygin <ivan.butygin@gmail.com>
Signed-off-by: Ivan Butygin <ivan.butygin@gmail.com>
Signed-off-by: Ivan Butygin <ivan.butygin@gmail.com>
Signed-off-by: Ivan Butygin <ivan.butygin@gmail.com>
Signed-off-by: Ivan Butygin <ivan.butygin@gmail.com>
Signed-off-by: Ivan Butygin <ivan.butygin@gmail.com>
Signed-off-by: Ivan Butygin <ivan.butygin@gmail.com>
Signed-off-by: Ivan Butygin <ivan.butygin@gmail.com>
Signed-off-by: Ivan Butygin <ivan.butygin@gmail.com>
13e2f8f to
23d2c66
Compare
affine.apply