Skip to content

Commit 994d882

Browse files
committed
[RISCV] Add an slli.uw pattern using zext for -riscv-experimental-rv64-legal-i32
We already had the pattern for GlobalISel. Move it over to SelectionDAG.
1 parent f7a759d commit 994d882

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

llvm/lib/Target/RISCV/RISCVGISel.td

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,6 @@ def : Pat<(i32 (sra GPR:$rs1, (i32 GPR:$rs2))), (SRAW GPR:$rs1, GPR:$rs2)>;
8787
def : Pat<(i32 (srl GPR:$rs1, (i32 GPR:$rs2))), (SRLW GPR:$rs1, GPR:$rs2)>;
8888
}
8989

90-
let Predicates = [HasStdExtZba, IsRV64] in {
91-
// This pattern is put here due to the fact that i32 is not a legal type
92-
// in SDISel for RV64, which is not the case in GISel.
93-
def : Pat<(shl (i64 (zext i32:$rs1)), uimm5:$shamt),
94-
(SLLI_UW GPR:$rs1, uimm5:$shamt)>;
95-
} // Predicates = [HasStdExtZba, IsRV64]
96-
9790
// Ptr type used in patterns with GlobalISelEmitter
9891
def PtrVT : PtrValueTypeByHwMode<XLenVT, 0>;
9992

llvm/lib/Target/RISCV/RISCVInstrInfoZb.td

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,9 +847,12 @@ def : Pat<(i32 (rotl GPR:$rs1, uimm5:$rs2)),
847847
} // Predicates = [HasStdExtZbbOrZbkb, IsRV64]
848848

849849
let Predicates = [HasStdExtZba, IsRV64] in {
850-
def : Pat<(zext GPR:$src), (ADD_UW GPR:$src, (XLenVT X0))>;
850+
def : Pat<(shl (i64 (zext i32:$rs1)), uimm5:$shamt),
851+
(SLLI_UW GPR:$rs1, uimm5:$shamt)>;
852+
851853
def : Pat<(i64 (add_non_imm12 (zext GPR:$rs1), GPR:$rs2)),
852854
(ADD_UW GPR:$rs1, GPR:$rs2)>;
855+
def : Pat<(zext GPR:$src), (ADD_UW GPR:$src, (XLenVT X0))>;
853856

854857
foreach i = {1,2,3} in {
855858
defvar shxadd = !cast<Instruction>("SH"#i#"ADD");

llvm/test/CodeGen/RISCV/rv64-legal-i32/rv64zba.ll

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,33 @@ define i128 @slliuw_2(i32 signext %0, ptr %1) {
4545
ret i128 %5
4646
}
4747

48+
define i128 @slliuw_3(i32 signext %0, ptr %1) {
49+
; RV64I-LABEL: slliuw_3:
50+
; RV64I: # %bb.0:
51+
; RV64I-NEXT: addi a0, a0, 1
52+
; RV64I-NEXT: slli a0, a0, 32
53+
; RV64I-NEXT: srli a0, a0, 32
54+
; RV64I-NEXT: slli a0, a0, 4
55+
; RV64I-NEXT: add a1, a1, a0
56+
; RV64I-NEXT: ld a0, 0(a1)
57+
; RV64I-NEXT: ld a1, 8(a1)
58+
; RV64I-NEXT: ret
59+
;
60+
; RV64ZBA-LABEL: slliuw_3:
61+
; RV64ZBA: # %bb.0:
62+
; RV64ZBA-NEXT: addi a0, a0, 1
63+
; RV64ZBA-NEXT: slli.uw a0, a0, 4
64+
; RV64ZBA-NEXT: add a1, a1, a0
65+
; RV64ZBA-NEXT: ld a0, 0(a1)
66+
; RV64ZBA-NEXT: ld a1, 8(a1)
67+
; RV64ZBA-NEXT: ret
68+
%add = add i32 %0, 1
69+
%3 = zext i32 %add to i64
70+
%4 = getelementptr inbounds i128, ptr %1, i64 %3
71+
%5 = load i128, ptr %4
72+
ret i128 %5
73+
}
74+
4875
define i64 @adduw(i64 %a, i64 %b) nounwind {
4976
; RV64I-LABEL: adduw:
5077
; RV64I: # %bb.0:

0 commit comments

Comments
 (0)