Skip to content

Commit 916c830

Browse files
committed
Revert "[RISCV][GISel] Remove unused isel patterns for s32 shifts with s64 shift amount."
This reverts commit 9e45e7f. I found a way that these can be used. I think it's a bug somewhere else that I need to address separately first.
1 parent e45b44c commit 916c830

File tree

2 files changed

+61
-3
lines changed

2 files changed

+61
-3
lines changed

llvm/lib/Target/RISCV/RISCVGISel.td

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ def : Pat<(XLenVT (sub GPR:$rs1, simm12Plus1:$imm)),
9595
let Predicates = [IsRV64] in {
9696
def : Pat<(i32 (sub GPR:$rs1, simm12Plus1i32:$imm)),
9797
(ADDIW GPR:$rs1, (i64 (NegImm $imm)))>;
98+
99+
def : Pat<(i32 (shl GPR:$rs1, (i32 GPR:$rs2))), (SLLW GPR:$rs1, GPR:$rs2)>;
100+
def : Pat<(i32 (sra GPR:$rs1, (i32 GPR:$rs2))), (SRAW GPR:$rs1, GPR:$rs2)>;
101+
def : Pat<(i32 (srl GPR:$rs1, (i32 GPR:$rs2))), (SRLW GPR:$rs1, GPR:$rs2)>;
98102
}
99103

100104
// Ptr type used in patterns with GlobalISelEmitter
@@ -191,9 +195,9 @@ def : PatGprGpr<sub, SUBW, i32, i32>;
191195
def : PatGprGpr<and, AND, i32, i32>;
192196
def : PatGprGpr<or, OR, i32, i32>;
193197
def : PatGprGpr<xor, XOR, i32, i32>;
194-
def : PatGprGpr<shl, SLLW, i32, i32>;
195-
def : PatGprGpr<srl, SRLW, i32, i32>;
196-
def : PatGprGpr<sra, SRAW, i32, i32>;
198+
def : PatGprGpr<shiftopw<shl>, SLLW, i32, i64>;
199+
def : PatGprGpr<shiftopw<srl>, SRLW, i32, i64>;
200+
def : PatGprGpr<shiftopw<sra>, SRAW, i32, i64>;
197201

198202
def : Pat<(i32 (add GPR:$rs1, simm12i32:$imm)),
199203
(ADDIW GPR:$rs1, (i64 (as_i64imm $imm)))>;

llvm/test/CodeGen/RISCV/GlobalISel/shift.ll

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,57 @@ define i16 @test_shl_i48(i48 %x) {
4646
%trunc = trunc i48 %shl to i16
4747
ret i16 %trunc
4848
}
49+
50+
define i16 @test_lshr_i48_2(i48 %x, i48 %y) {
51+
; RV32-LABEL: test_lshr_i48_2:
52+
; RV32: # %bb.0:
53+
; RV32-NEXT: andi a2, a2, 15
54+
; RV32-NEXT: srl a0, a0, a2
55+
; RV32-NEXT: ret
56+
;
57+
; RV64-LABEL: test_lshr_i48_2:
58+
; RV64: # %bb.0:
59+
; RV64-NEXT: andi a1, a1, 15
60+
; RV64-NEXT: srlw a0, a0, a1
61+
; RV64-NEXT: ret
62+
%and = and i48 %y, 15
63+
%lshr = lshr i48 %x, %and
64+
%trunc = trunc i48 %lshr to i16
65+
ret i16 %trunc
66+
}
67+
68+
define i16 @test_ashr_i48_2(i48 %x, i48 %y) {
69+
; RV32-LABEL: test_ashr_i48_2:
70+
; RV32: # %bb.0:
71+
; RV32-NEXT: andi a2, a2, 15
72+
; RV32-NEXT: sra a0, a0, a2
73+
; RV32-NEXT: ret
74+
;
75+
; RV64-LABEL: test_ashr_i48_2:
76+
; RV64: # %bb.0:
77+
; RV64-NEXT: andi a1, a1, 15
78+
; RV64-NEXT: sraw a0, a0, a1
79+
; RV64-NEXT: ret
80+
%and = and i48 %y, 15
81+
%ashr = ashr i48 %x, %and
82+
%trunc = trunc i48 %ashr to i16
83+
ret i16 %trunc
84+
}
85+
86+
define i16 @test_shl_i48_2(i48 %x, i48 %y) {
87+
; RV32-LABEL: test_shl_i48_2:
88+
; RV32: # %bb.0:
89+
; RV32-NEXT: andi a2, a2, 15
90+
; RV32-NEXT: sll a0, a0, a2
91+
; RV32-NEXT: ret
92+
;
93+
; RV64-LABEL: test_shl_i48_2:
94+
; RV64: # %bb.0:
95+
; RV64-NEXT: andi a1, a1, 15
96+
; RV64-NEXT: sllw a0, a0, a1
97+
; RV64-NEXT: ret
98+
%and = and i48 %y, 15
99+
%shl = shl i48 %x, %and
100+
%trunc = trunc i48 %shl to i16
101+
ret i16 %trunc
102+
}

0 commit comments

Comments
 (0)