-
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
Changes from 6 commits
d44abb5
c6145c9
c4f9582
9b71670
2ce0036
12631f6
eb685b0
5bd9c00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,50 @@ | |
// CHECK-NEXT: %addf = arith.addf %lhsf32, %rhsf32 : f32 | ||
// CHECK-NEXT: %addf_vector = arith.addf %lhsvec, %rhsvec : vector<4xf32> | ||
// CHECK-NEXT: "test.op"(%addf, %addf_vector) : (f32, vector<4xf32>) -> () | ||
|
||
func.func @test_const_const() { | ||
%a = arith.constant 2.9979 : f32 | ||
%b = arith.constant 3.1415 : f32 | ||
%1 = arith.addf %a, %b : f32 | ||
%2 = arith.subf %a, %b : f32 | ||
%3 = arith.mulf %a, %b : f32 | ||
%4 = arith.divf %a, %b : f32 | ||
"test.op"(%1, %2, %3, %4) : (f32, f32, f32, f32) -> () | ||
|
||
return | ||
|
||
// CHECK-LABEL: @test_const_const | ||
// CHECK-NEXT: %0 = arith.constant 6.139400e+00 : f32 | ||
// CHECK-NEXT: %1 = arith.constant -1.436000e-01 : f32 | ||
// CHECK-NEXT: %2 = arith.constant 9.417903e+00 : f32 | ||
// CHECK-NEXT: %3 = arith.constant 9.542894e-01 : f32 | ||
// CHECK-NEXT: "test.op"(%0, %1, %2, %3) : (f32, f32, f32, f32) -> () | ||
} | ||
|
||
func.func @test_const_var_const() { | ||
%0, %1 = "test.op"() : () -> (f32, f32) | ||
%a = arith.constant 2.9979 : f32 | ||
%b = arith.constant 3.1415 : f32 | ||
%c = arith.constant 4.1415 : f32 | ||
%d = arith.constant 5.1415 : f32 | ||
|
||
%2 = arith.mulf %0, %a : f32 | ||
%3 = arith.mulf %2, %b : f32 | ||
|
||
%4 = arith.mulf %0, %c fastmath<reassoc> : f32 | ||
%5 = arith.mulf %4, %d fastmath<fast> : f32 | ||
|
||
"test.op"(%3, %5) : (f32, f32) -> () | ||
|
||
return | ||
|
||
// CHECK-LABEL: @test_const_var_const | ||
// CHECK-NEXT: %0, %1 = "test.op"() : () -> (f32, f32) | ||
// CHECK-NEXT: %a = arith.constant 2.997900e+00 : f32 | ||
// CHECK-NEXT: %b = arith.constant 3.141500e+00 : f32 | ||
// 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 commentThe reason will be displayed to describe this comment to others. Learn more. Is the resulting flag the There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
// CHECK-NEXT: "test.op"(%3, %5) : (f32, 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.
I would also prefer to see the checks appear above the tests here, but feel free to ignore