Skip to content

Commit 253317e

Browse files
committed
[RISCV] Implement codegen for XAndesPerf lea instructions
This patch add the patterns for generating XAndesPerf lea instructions. The operation of LEA family instructions is: rd = rs1 + rs2 * (the number of bytes) The variants with *.ze suffix are RV64 only and its operation is: rd = rs1 + ZE32(rs2[31:0]) * (the number of bytes)
1 parent 23c3c4e commit 253317e

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfoXAndes.td

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,3 +356,28 @@ def NDS_LDGP : NDSRVInstLDGP<0b011, "nds.ldgp">;
356356
def NDS_SDGP : NDSRVInstSDGP<0b111, "nds.sdgp">;
357357
} // Predicates = [HasVendorXAndesPerf, IsRV64]
358358
} // DecoderNamespace = "XAndes"
359+
360+
// Patterns
361+
362+
let Predicates = [HasVendorXAndesPerf] in {
363+
class NDS_LEAPat<int shamt, RVInstR Inst>
364+
: Pat<(add (XLenVT GPR:$rs1), (shl GPR:$rs2, (XLenVT shamt))),
365+
(Inst GPR:$rs1, GPR:$rs2)>;
366+
367+
def : NDS_LEAPat<1, NDS_LEA_H>;
368+
def : NDS_LEAPat<2, NDS_LEA_W>;
369+
def : NDS_LEAPat<3, NDS_LEA_D>;
370+
} // Predicates = [HasVendorXAndesPerf]
371+
372+
let Predicates = [HasVendorXAndesPerf, IsRV64] in {
373+
def : Pat<(add (XLenVT GPR:$rs1), (zexti32 (i64 GPR:$rs2))),
374+
(NDS_LEA_B_ZE GPR:$rs1, GPR:$rs2)>;
375+
376+
class NDS_LEA_ZEPat<int shamt, RVInstR Inst>
377+
: Pat<(add GPR:$rs1, (shl (zexti32 (XLenVT GPR:$rs2)), (XLenVT shamt))),
378+
(Inst GPR:$rs1, GPR:$rs2)>;
379+
380+
def : NDS_LEA_ZEPat<1, NDS_LEA_H_ZE>;
381+
def : NDS_LEA_ZEPat<2, NDS_LEA_W_ZE>;
382+
def : NDS_LEA_ZEPat<3, NDS_LEA_D_ZE>;
383+
} // Predicates = [HasVendorXAndesPerf, IsRV64]
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -O0 -mtriple=riscv32 -mattr=+xandesperf -verify-machineinstrs < %s \
3+
; RUN: | FileCheck %s
4+
5+
define i32 @lea_h(i32 %a, i32 %b) {
6+
; CHECK-LABEL: lea_h:
7+
; CHECK: # %bb.0:
8+
; CHECK-NEXT: nds.lea.h a0, a0, a1
9+
; CHECK-NEXT: ret
10+
%shl = shl i32 %b, 1
11+
%ret = add i32 %a, %shl
12+
ret i32 %ret
13+
}
14+
15+
define i32 @lea_w(i32 %a, i32 %b) {
16+
; CHECK-LABEL: lea_w:
17+
; CHECK: # %bb.0:
18+
; CHECK-NEXT: nds.lea.w a0, a0, a1
19+
; CHECK-NEXT: ret
20+
%shl = shl i32 %b, 2
21+
%ret = add i32 %a, %shl
22+
ret i32 %ret
23+
}
24+
25+
define i32 @lea_d(i32 %a, i32 %b) {
26+
; CHECK-LABEL: lea_d:
27+
; CHECK: # %bb.0:
28+
; CHECK-NEXT: nds.lea.d a0, a0, a1
29+
; CHECK-NEXT: ret
30+
%shl = shl i32 %b, 3
31+
%ret = add i32 %a, %shl
32+
ret i32 %ret
33+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2+
; RUN: llc -mtriple=riscv64 -mattr=+xandesperf -verify-machineinstrs < %s \
3+
; RUN: | FileCheck %s
4+
5+
define i64 @lea_b_ze(i32 %a, i64 %b) {
6+
; CHECK-LABEL: lea_b_ze:
7+
; CHECK: # %bb.0:
8+
; CHECK-NEXT: nds.lea.b.ze a0, a1, a0
9+
; CHECK-NEXT: ret
10+
%conv = zext i32 %a to i64
11+
%add = add i64 %conv, %b
12+
ret i64 %add
13+
}
14+
15+
define i64 @lea_h_ze(i32 %a, i64 %b) {
16+
; CHECK-LABEL: lea_h_ze:
17+
; CHECK: # %bb.0:
18+
; CHECK-NEXT: nds.lea.h.ze a0, a1, a0
19+
; CHECK-NEXT: ret
20+
%conv = zext i32 %a to i64
21+
%shl = shl nuw nsw i64 %conv, 1
22+
%add = add i64 %shl, %b
23+
ret i64 %add
24+
}
25+
26+
define i64 @lea_w_ze(i32 %a, i64 %b) {
27+
; CHECK-LABEL: lea_w_ze:
28+
; CHECK: # %bb.0:
29+
; CHECK-NEXT: nds.lea.w.ze a0, a1, a0
30+
; CHECK-NEXT: ret
31+
%conv = zext i32 %a to i64
32+
%shl = shl nuw nsw i64 %conv, 2
33+
%add = add i64 %shl, %b
34+
ret i64 %add
35+
}
36+
37+
define i64 @lea_d_ze(i32 %a, i64 %b) {
38+
; CHECK-LABEL: lea_d_ze:
39+
; CHECK: # %bb.0:
40+
; CHECK-NEXT: nds.lea.d.ze a0, a1, a0
41+
; CHECK-NEXT: ret
42+
%conv = zext i32 %a to i64
43+
%shl = shl nuw nsw i64 %conv, 3
44+
%add = add i64 %shl, %b
45+
ret i64 %add
46+
}

0 commit comments

Comments
 (0)