-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[RISCV] Implement codegen for XAndesPerf lea instructions #137925
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 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
253317e
[RISCV] Implement codegen for XAndesPerf lea instructions
tclin914 ffb5d39
Make the patterns for Zba be multiclass/class that we can reuse it.
tclin914 1dea0f3
Reuse the patterns from Zba for XAndesPerf lea instructions
tclin914 9fb0458
indent the body in multiclass by 2 spaces.
tclin914 15980a1
Switch the position of rs1 and rs2 for lea instruction
tclin914 4d20459
Change the order of rs1 and rs1 in ins rather than in argstr
tclin914 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -356,3 +356,28 @@ def NDS_LDGP : NDSRVInstLDGP<0b011, "nds.ldgp">; | |
| def NDS_SDGP : NDSRVInstSDGP<0b111, "nds.sdgp">; | ||
| } // Predicates = [HasVendorXAndesPerf, IsRV64] | ||
| } // DecoderNamespace = "XAndes" | ||
|
|
||
| // Patterns | ||
|
|
||
| let Predicates = [HasVendorXAndesPerf] in { | ||
| class NDS_LEAPat<int shamt, RVInstR Inst> | ||
| : Pat<(add (XLenVT GPR:$rs1), (shl GPR:$rs2, (XLenVT shamt))), | ||
| (Inst GPR:$rs1, GPR:$rs2)>; | ||
|
|
||
| def : NDS_LEAPat<1, NDS_LEA_H>; | ||
| def : NDS_LEAPat<2, NDS_LEA_W>; | ||
| def : NDS_LEAPat<3, NDS_LEA_D>; | ||
| } // Predicates = [HasVendorXAndesPerf] | ||
|
|
||
| let Predicates = [HasVendorXAndesPerf, IsRV64] in { | ||
| def : Pat<(add (XLenVT GPR:$rs1), (zexti32 (i64 GPR:$rs2))), | ||
| (NDS_LEA_B_ZE GPR:$rs1, GPR:$rs2)>; | ||
|
|
||
| class NDS_LEA_ZEPat<int shamt, RVInstR Inst> | ||
| : Pat<(add GPR:$rs1, (shl (zexti32 (XLenVT GPR:$rs2)), (XLenVT shamt))), | ||
|
||
| (Inst GPR:$rs1, GPR:$rs2)>; | ||
|
|
||
| def : NDS_LEA_ZEPat<1, NDS_LEA_H_ZE>; | ||
| def : NDS_LEA_ZEPat<2, NDS_LEA_W_ZE>; | ||
| def : NDS_LEA_ZEPat<3, NDS_LEA_D_ZE>; | ||
| } // Predicates = [HasVendorXAndesPerf, IsRV64] | ||
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,33 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py | ||
| ; RUN: llc -O0 -mtriple=riscv32 -mattr=+xandesperf -verify-machineinstrs < %s \ | ||
| ; RUN: | FileCheck %s | ||
|
|
||
| define i32 @lea_h(i32 %a, i32 %b) { | ||
| ; CHECK-LABEL: lea_h: | ||
| ; CHECK: # %bb.0: | ||
| ; CHECK-NEXT: nds.lea.h a0, a0, a1 | ||
| ; CHECK-NEXT: ret | ||
| %shl = shl i32 %b, 1 | ||
| %ret = add i32 %a, %shl | ||
| ret i32 %ret | ||
| } | ||
|
|
||
| define i32 @lea_w(i32 %a, i32 %b) { | ||
| ; CHECK-LABEL: lea_w: | ||
| ; CHECK: # %bb.0: | ||
| ; CHECK-NEXT: nds.lea.w a0, a0, a1 | ||
| ; CHECK-NEXT: ret | ||
| %shl = shl i32 %b, 2 | ||
| %ret = add i32 %a, %shl | ||
| ret i32 %ret | ||
| } | ||
|
|
||
| define i32 @lea_d(i32 %a, i32 %b) { | ||
| ; CHECK-LABEL: lea_d: | ||
| ; CHECK: # %bb.0: | ||
| ; CHECK-NEXT: nds.lea.d a0, a0, a1 | ||
| ; CHECK-NEXT: ret | ||
| %shl = shl i32 %b, 3 | ||
| %ret = add i32 %a, %shl | ||
| ret i32 %ret | ||
| } |
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,46 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py | ||
| ; RUN: llc -mtriple=riscv64 -mattr=+xandesperf -verify-machineinstrs < %s \ | ||
| ; RUN: | FileCheck %s | ||
|
|
||
| define i64 @lea_b_ze(i32 %a, i64 %b) { | ||
| ; CHECK-LABEL: lea_b_ze: | ||
| ; CHECK: # %bb.0: | ||
| ; CHECK-NEXT: nds.lea.b.ze a0, a1, a0 | ||
| ; CHECK-NEXT: ret | ||
| %conv = zext i32 %a to i64 | ||
| %add = add i64 %conv, %b | ||
| ret i64 %add | ||
| } | ||
|
|
||
| define i64 @lea_h_ze(i32 %a, i64 %b) { | ||
| ; CHECK-LABEL: lea_h_ze: | ||
| ; CHECK: # %bb.0: | ||
| ; CHECK-NEXT: nds.lea.h.ze a0, a1, a0 | ||
| ; CHECK-NEXT: ret | ||
| %conv = zext i32 %a to i64 | ||
| %shl = shl nuw nsw i64 %conv, 1 | ||
| %add = add i64 %shl, %b | ||
| ret i64 %add | ||
| } | ||
|
|
||
| define i64 @lea_w_ze(i32 %a, i64 %b) { | ||
| ; CHECK-LABEL: lea_w_ze: | ||
| ; CHECK: # %bb.0: | ||
| ; CHECK-NEXT: nds.lea.w.ze a0, a1, a0 | ||
| ; CHECK-NEXT: ret | ||
| %conv = zext i32 %a to i64 | ||
| %shl = shl nuw nsw i64 %conv, 2 | ||
| %add = add i64 %shl, %b | ||
| ret i64 %add | ||
| } | ||
|
|
||
| define i64 @lea_d_ze(i32 %a, i64 %b) { | ||
| ; CHECK-LABEL: lea_d_ze: | ||
| ; CHECK: # %bb.0: | ||
| ; CHECK-NEXT: nds.lea.d.ze a0, a1, a0 | ||
| ; CHECK-NEXT: ret | ||
| %conv = zext i32 %a to i64 | ||
| %shl = shl nuw nsw i64 %conv, 3 | ||
| %add = add i64 %shl, %b | ||
| ret i64 %add | ||
| } |
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.
You probably want to use
add_like_non_imm12instead ofadd. That's what we do for sh1add/sh2add/sh3add from Zba. That will handleor disjointand prevent using the instruction if an ADDI could be used.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.
Thanks for pointing that out. I've updated the patterns for Zba to be multiclass/class so they can be reused.