-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[RISCV][GISel] Support G_ROTL/G_ROTR with Zbb. #72825
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
llvm/test/CodeGen/RISCV/GlobalISel/instruction-select/rotate-rv32.mir
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py | ||
# RUN: llc -mtriple=riscv32 -mattr=+zbb -run-pass=instruction-select \ | ||
# RUN: -simplify-mir -verify-machineinstrs %s -o - | FileCheck %s | ||
|
||
--- | ||
name: rotl_i32 | ||
legalized: true | ||
regBankSelected: true | ||
body: | | ||
bb.0: | ||
liveins: $x10, $x11 | ||
|
||
; CHECK-LABEL: name: rotl_i32 | ||
; CHECK: liveins: $x10, $x11 | ||
; CHECK-NEXT: {{ $}} | ||
; CHECK-NEXT: [[COPY:%[0-9]+]]:gpr = COPY $x10 | ||
; CHECK-NEXT: [[COPY1:%[0-9]+]]:gpr = COPY $x11 | ||
; CHECK-NEXT: [[ROL:%[0-9]+]]:gpr = ROL [[COPY]], [[COPY1]] | ||
; CHECK-NEXT: $x10 = COPY [[ROL]] | ||
; CHECK-NEXT: PseudoRET implicit $x10 | ||
%0:gprb(s32) = COPY $x10 | ||
%1:gprb(s32) = COPY $x11 | ||
%2:gprb(s32) = G_ROTL %0, %1(s32) | ||
$x10 = COPY %2(s32) | ||
PseudoRET implicit $x10 | ||
|
||
... | ||
--- | ||
name: rotr_i32 | ||
legalized: true | ||
regBankSelected: true | ||
body: | | ||
bb.0: | ||
liveins: $x10, $x11 | ||
|
||
; CHECK-LABEL: name: rotr_i32 | ||
; CHECK: liveins: $x10, $x11 | ||
; CHECK-NEXT: {{ $}} | ||
; CHECK-NEXT: [[COPY:%[0-9]+]]:gpr = COPY $x10 | ||
; CHECK-NEXT: [[COPY1:%[0-9]+]]:gpr = COPY $x11 | ||
; CHECK-NEXT: [[ROR:%[0-9]+]]:gpr = ROR [[COPY]], [[COPY1]] | ||
; CHECK-NEXT: $x10 = COPY [[ROR]] | ||
; CHECK-NEXT: PseudoRET implicit $x10 | ||
%0:gprb(s32) = COPY $x10 | ||
%1:gprb(s32) = COPY $x11 | ||
%2:gprb(s32) = G_ROTR %0, %1(s32) | ||
$x10 = COPY %2(s32) | ||
PseudoRET implicit $x10 | ||
|
||
... | ||
--- | ||
name: rotl_imm_i32 | ||
legalized: true | ||
regBankSelected: true | ||
body: | | ||
bb.0: | ||
liveins: $x10 | ||
|
||
; CHECK-LABEL: name: rotl_imm_i32 | ||
; CHECK: liveins: $x10 | ||
; CHECK-NEXT: {{ $}} | ||
; CHECK-NEXT: [[COPY:%[0-9]+]]:gpr = COPY $x10 | ||
; CHECK-NEXT: [[RORI:%[0-9]+]]:gpr = RORI [[COPY]], 27 | ||
; CHECK-NEXT: $x10 = COPY [[RORI]] | ||
; CHECK-NEXT: PseudoRET implicit $x10 | ||
%0:gprb(s32) = COPY $x10 | ||
%1:gprb(s32) = G_CONSTANT i32 5 | ||
%2:gprb(s32) = G_ROTL %0, %1(s32) | ||
$x10 = COPY %2(s32) | ||
PseudoRET implicit $x10 | ||
|
||
... | ||
--- | ||
name: rotr_imm_i32 | ||
legalized: true | ||
regBankSelected: true | ||
body: | | ||
bb.0: | ||
liveins: $x10 | ||
|
||
; CHECK-LABEL: name: rotr_imm_i32 | ||
; CHECK: liveins: $x10 | ||
; CHECK-NEXT: {{ $}} | ||
; CHECK-NEXT: [[COPY:%[0-9]+]]:gpr = COPY $x10 | ||
; CHECK-NEXT: [[RORI:%[0-9]+]]:gpr = RORI [[COPY]], 5 | ||
; CHECK-NEXT: $x10 = COPY [[RORI]] | ||
; CHECK-NEXT: PseudoRET implicit $x10 | ||
%0:gprb(s32) = COPY $x10 | ||
%1:gprb(s32) = G_CONSTANT i32 5 | ||
%2:gprb(s32) = G_ROTR %0, %1(s32) | ||
$x10 = COPY %2(s32) | ||
PseudoRET implicit $x10 | ||
|
||
... |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 this converting the
s32 = G_ROT s32
into as32 = G_ROT s64
? I am surprised that SDAG is built on mismatching types for this operation. Do you mind sharing with me why SDAG takes this approach instead of widening both operands to sXLen?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.
it's turning s32 = G_ROT s32, s32 to s32 = G_ROT s32, s64. The last operand is the rotate amount.
There's no way to widen the first type and have it still be the same rotate since there would be extra bits.
Shifts and rotates allow the shift/rotate amount to differ from the other type. In SelectionDAG this is controlled by getScalarShiftAmountTy which defaults to pointer size.
The s32 = G_ROT s32, s64 pattern was added to SelectionDAG for my legal i32 work. Prior to that we used a custom RISCVISD::RORW/ROTW node on RV64.
I may ultimately change the scalar shift amount type to s32 for RV64, for both s32 and s64 but I haven't decided yet. Only the lower 5 or 6 bits are used by hardware.