-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[RISCV] Improve instruction selection for most significant bit extraction #151687
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 |
|---|---|---|
|
|
@@ -187,14 +187,14 @@ define i64 @bittest_31_i64(i64 %a) nounwind { | |
| ; | ||
| ; RV64ZBS-LABEL: bittest_31_i64: | ||
| ; RV64ZBS: # %bb.0: | ||
| ; RV64ZBS-NEXT: not a0, a0 | ||
| ; RV64ZBS-NEXT: bexti a0, a0, 31 | ||
| ; RV64ZBS-NEXT: srliw a0, a0, 31 | ||
| ; RV64ZBS-NEXT: xori a0, a0, 1 | ||
| ; RV64ZBS-NEXT: ret | ||
| ; | ||
| ; RV64XTHEADBS-LABEL: bittest_31_i64: | ||
| ; RV64XTHEADBS: # %bb.0: | ||
| ; RV64XTHEADBS-NEXT: not a0, a0 | ||
| ; RV64XTHEADBS-NEXT: th.tst a0, a0, 31 | ||
| ; RV64XTHEADBS-NEXT: srliw a0, a0, 31 | ||
| ; RV64XTHEADBS-NEXT: xori a0, a0, 1 | ||
| ; RV64XTHEADBS-NEXT: ret | ||
| %shr = lshr i64 %a, 31 | ||
| %not = xor i64 %shr, -1 | ||
|
|
@@ -3507,3 +3507,77 @@ define void @bit_64_1_nz_branch_i64(i64 %0) { | |
| 5: | ||
| ret void | ||
| } | ||
|
|
||
| define i32 @bittest_31_andeq0_i64(i64 %x) { | ||
| ; RV32-LABEL: bittest_31_andeq0_i64: | ||
| ; RV32: # %bb.0: | ||
| ; RV32-NEXT: srli a0, a0, 31 | ||
| ; RV32-NEXT: xori a0, a0, 1 | ||
| ; RV32-NEXT: ret | ||
| ; | ||
| ; RV64-LABEL: bittest_31_andeq0_i64: | ||
| ; RV64: # %bb.0: | ||
| ; RV64-NEXT: srliw a0, a0, 31 | ||
| ; RV64-NEXT: xori a0, a0, 1 | ||
| ; RV64-NEXT: ret | ||
| %and = and i64 %x, 2147483648 | ||
| %cmp = icmp eq i64 %and, 0 | ||
| %conv = zext i1 %cmp to i32 | ||
| ret i32 %conv | ||
| } | ||
|
|
||
| define i32 @bittest_63_andeq0_i64(i64 %x) { | ||
| ; RV32-LABEL: bittest_63_andeq0_i64: | ||
| ; RV32: # %bb.0: | ||
| ; RV32-NEXT: srli a1, a1, 31 | ||
| ; RV32-NEXT: xori a0, a1, 1 | ||
| ; RV32-NEXT: ret | ||
| ; | ||
| ; RV64-LABEL: bittest_63_andeq0_i64: | ||
| ; RV64: # %bb.0: | ||
| ; RV64-NEXT: srli a0, a0, 63 | ||
| ; RV64-NEXT: xori a0, a0, 1 | ||
| ; RV64-NEXT: ret | ||
| %and = and i64 %x, 9223372036854775808 | ||
|
Collaborator
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. @pfusik Do you have examples of this pattern occurring? It seems non-canonical according to InstCombine.
Contributor
Author
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. https://github.com/dtcxzyw/llvm-codegen-benchmark |
||
| %cmp = icmp eq i64 %and, 0 | ||
| %conv = zext i1 %cmp to i32 | ||
| ret i32 %conv | ||
| } | ||
|
|
||
| define i32 @bittest_31_slt0_i32(i32 %x, i1 %y) { | ||
| ; RV32-LABEL: bittest_31_slt0_i32: | ||
| ; RV32: # %bb.0: | ||
| ; RV32-NEXT: srli a0, a0, 31 | ||
| ; RV32-NEXT: and a0, a0, a1 | ||
| ; RV32-NEXT: ret | ||
| ; | ||
| ; RV64-LABEL: bittest_31_slt0_i32: | ||
| ; RV64: # %bb.0: | ||
| ; RV64-NEXT: srliw a0, a0, 31 | ||
| ; RV64-NEXT: and a0, a0, a1 | ||
| ; RV64-NEXT: ret | ||
| %cmp = icmp slt i32 %x, 0 | ||
| %and = and i1 %cmp, %y | ||
| %ext = zext i1 %and to i32 | ||
| ret i32 %ext | ||
| } | ||
|
|
||
| define i32 @bittest_63_slt0_i64(i32 %x, i1 %y) { | ||
| ; RV32-LABEL: bittest_63_slt0_i64: | ||
| ; RV32: # %bb.0: | ||
| ; RV32-NEXT: srai a0, a0, 31 | ||
|
||
| ; RV32-NEXT: srli a0, a0, 31 | ||
| ; RV32-NEXT: and a0, a0, a1 | ||
| ; RV32-NEXT: ret | ||
| ; | ||
| ; RV64-LABEL: bittest_63_slt0_i64: | ||
| ; RV64: # %bb.0: | ||
| ; RV64-NEXT: srliw a0, a0, 31 | ||
| ; RV64-NEXT: and a0, a0, a1 | ||
| ; RV64-NEXT: ret | ||
| %ext = sext i32 %x to i64 | ||
| %cmp = icmp slt i64 %ext, 0 | ||
| %and = and i1 %cmp, %y | ||
| %cond = zext i1 %and to i32 | ||
| ret i32 %cond | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.