Skip to content
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

dialects: (arith) add addi constant propagation #3563

Merged
merged 3 commits into from
Dec 4, 2024

Conversation

alexarice
Copy link
Collaborator

Moves constants to the right for an addi operation, similar to what #3557 did for muli. Also replaces AddImmediateZero by AddiIdentityRight, which removes constant zeros on the right of an addition instead of the left of an addition like the previous pattern did.

Updates interactive tests (and driveby fixes the constant zero being given the SSA value name %two in this test).

@alexarice alexarice self-assigned this Dec 3, 2024
@alexarice alexarice added the dialects Changes on the dialects label Dec 3, 2024
Copy link

codecov bot commented Dec 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.39%. Comparing base (d81d66d) to head (5c3b484).
Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3563      +/-   ##
==========================================
- Coverage   90.39%   90.39%   -0.01%     
==========================================
  Files         467      467              
  Lines       58857    58870      +13     
  Branches     5606     5609       +3     
==========================================
+ Hits        53206    53216      +10     
- Misses       4207     4208       +1     
- Partials     1444     1446       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines 114 to 122
%zero_plus = arith.addi %c0, %a : i32
%plus_zero = arith.addi %a, %c0 : i32

// CHECK: "test.op"(%a, %a) {"identity addition check"} : (i32, i32) -> ()
"test.op"(%one_times, %times_one) {"identity addition check"} : (i32, i32) -> ()

// CHECK: %plus_const = arith.addi %a, %c2 : i32
%plus_const = arith.addi %c2, %a : i32
"test.op"(%plus_const) : (i32) -> ()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
%zero_plus = arith.addi %c0, %a : i32
%plus_zero = arith.addi %a, %c0 : i32
// CHECK: "test.op"(%a, %a) {"identity addition check"} : (i32, i32) -> ()
"test.op"(%one_times, %times_one) {"identity addition check"} : (i32, i32) -> ()
// CHECK: %plus_const = arith.addi %a, %c2 : i32
%plus_const = arith.addi %c2, %a : i32
"test.op"(%plus_const) : (i32) -> ()
%zero_plus = arith.addi %c0, %a : i32
%plus_zero = arith.addi %a, %c0 : i32
// CHECK: %plus_const = arith.addi %a, %c2 : i32
%plus_const = arith.addi %c2, %a : i32
"test.op"(%plus_const) : (i32) -> ()

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unless I'm missing something, it looks like this is a copy/paste from above, but is not necessary

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooh, it is necessary but should be %zero_plus and %plus_zero instead of %one_times and %times_one

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was also a copy paste

@alexarice
Copy link
Collaborator Author

Have fixed the test and resolved the conflict

@alexarice alexarice merged commit 494a12f into main Dec 4, 2024
15 checks passed
@alexarice alexarice deleted the alexarice/addi-canonicalization branch December 4, 2024 10:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dialects Changes on the dialects
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants