-
Notifications
You must be signed in to change notification settings - Fork 25
[WIP] A collection of affine expressions utils #671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
Signed-off-by: Ivan Butygin <[email protected]>
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
affine.apply