-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[RISCV] Fold (X & (7 << 29)) == 0 -> (srliw X, 29) == 0 for RV64. #156769
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
Changes from all commits
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 |
|---|---|---|
|
|
@@ -64,3 +64,37 @@ define i1 @test4(i64 %x) { | |
| %b = icmp eq i64 %a, 0 | ||
| ret i1 %b | ||
| } | ||
|
|
||
| define i1 @test5(i64 %x) { | ||
|
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. Can you precommit the tests so we can see prior codegen? 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.
They are in separate commits in the PR. |
||
| ; RV32-LABEL: test5: | ||
| ; RV32: # %bb.0: | ||
| ; RV32-NEXT: srli a0, a0, 29 | ||
| ; RV32-NEXT: seqz a0, a0 | ||
| ; RV32-NEXT: ret | ||
| ; | ||
| ; RV64-LABEL: test5: | ||
| ; RV64: # %bb.0: | ||
| ; RV64-NEXT: srliw a0, a0, 29 | ||
| ; RV64-NEXT: seqz a0, a0 | ||
| ; RV64-NEXT: ret | ||
| %a = and i64 %x, u0xE0000000 | ||
| %b = icmp eq i64 %a, 0 | ||
| ret i1 %b | ||
| } | ||
|
|
||
| define i1 @test6(i64 %x) { | ||
| ; RV32-LABEL: test6: | ||
| ; RV32: # %bb.0: | ||
| ; RV32-NEXT: srli a0, a0, 29 | ||
| ; RV32-NEXT: snez a0, a0 | ||
| ; RV32-NEXT: ret | ||
| ; | ||
| ; RV64-LABEL: test6: | ||
| ; RV64: # %bb.0: | ||
| ; RV64-NEXT: srliw a0, a0, 29 | ||
| ; RV64-NEXT: snez a0, a0 | ||
| ; RV64-NEXT: ret | ||
| %a = and i64 %x, u0xE0000000 | ||
| %b = icmp ne i64 %a, 0 | ||
| ret i1 %b | ||
| } | ||
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.
To make sure I follow, this is handling the case where a 0..01111..0 mask (with the 0..0 being exactly the high 32 bits), by masking out the bottom 32 and then doing the same shift compare as above? And this happens to fold into a srlw because we only care about the zero-ness of the shift, so extending bit 31 is fine?
If so, can we generalize this by replacing the AND with a SHL to clear the high bits, and adjusting the SRL amount?
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.
A: We already were generating the shift pair sequence, and this an optimization on that.
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.
srliw is filling zeros to any bits in the result above the original bit 31. I'm not sure if that's what you mean by "extending bit 31"?. It would also be correct to use sraiw for this case which would duplicate the original bit 31.
Yes
Uh oh!
There was an error while loading. Please reload this page.
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're generating a shift pair sequence for the 32 leading zero case, but I don't think we do for other leading zero amounts. Which I think is what you were suggesting?
A general 0..0111..0 AND mask requires 3 shifts to implement and we don't do that currently. If we know the user is a seteq/setne we can use 2 shifts because we can move the bits to the lsbs of the compare.