-
Notifications
You must be signed in to change notification settings - Fork 73
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
transformations: (canonicalize) Arith const reassociation #3364
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3364 +/- ##
=======================================
Coverage 90.10% 90.10%
=======================================
Files 449 449
Lines 56666 56686 +20
Branches 5440 5443 +3
=======================================
+ Hits 51060 51079 +19
Misses 4168 4168
- Partials 1438 1439 +1 ☔ View full report in Codecov by Sentry. |
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.
Nice! I just had a qustion about the flags to add in the new created operation, but otherwise everything is good! Thanks!
// CHECK-NEXT: %2 = arith.mulf %0, %a : f32 | ||
// CHECK-NEXT: %3 = arith.mulf %2, %b : f32 | ||
// CHECK-NEXT: %4 = arith.constant 2.129352e+01 : f32 | ||
// CHECK-NEXT: %5 = arith.mulf %4, %0 fastmath<fast> : f32 |
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.
Is the resulting flag the or
of both operations?
I am out of my depth here, is it what MLIR does?
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.
Yes, since we're essentially folding two ops into one, I wasn't entirely sure how to set the flags on the new op. The union set of both ops seemed like a cleaner option as compared to picking either one at random. I am not entirely sure myself as to how mlir would resolve such a case.
|
||
return | ||
|
||
// CHECK-LABEL: @test_const_var_const |
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 would also prefer to see the checks appear above the tests here, but feel free to ignore
This adds the second of two canonicalisation patterns for
FloatingPointLikeBinaryOperation
s onarith.constants
.(const1 * var) * const2
are rewritten as(const1 * const2) * var
iff thefastmath<reassoc>
orfastmath<fast>
flags are set, and if the ops are multiplications or additions. Note, this is not currently implemented in upstream mlir.See here to check how it works in upstream mlir.
Note, these canonicalisations currently do not support container types.