55define i16 @test_lshr_i48 (i48 %x ) {
66; RV32-LABEL: test_lshr_i48:
77; RV32: # %bb.0:
8+ ; RV32-NEXT: lui a2, 16
9+ ; RV32-NEXT: addi a2, a2, -1
10+ ; RV32-NEXT: and a1, a1, a2
811; RV32-NEXT: srli a0, a0, 16
12+ ; RV32-NEXT: slli a1, a1, 16
13+ ; RV32-NEXT: or a0, a0, a1
914; RV32-NEXT: ret
1015;
1116; RV64-LABEL: test_lshr_i48:
1217; RV64: # %bb.0:
13- ; RV64-NEXT: srliw a0, a0, 16
18+ ; RV64-NEXT: li a1, -1
19+ ; RV64-NEXT: srli a1, a1, 16
20+ ; RV64-NEXT: and a0, a0, a1
21+ ; RV64-NEXT: srli a0, a0, 16
1422; RV64-NEXT: ret
1523 %lshr = lshr i48 %x , 16
1624 %trunc = trunc i48 %lshr to i16
@@ -20,12 +28,18 @@ define i16 @test_lshr_i48(i48 %x) {
2028define i16 @test_ashr_i48 (i48 %x ) {
2129; RV32-LABEL: test_ashr_i48:
2230; RV32: # %bb.0:
23- ; RV32-NEXT: srai a0, a0, 16
31+ ; RV32-NEXT: slli a1, a1, 16
32+ ; RV32-NEXT: srai a1, a1, 16
33+ ; RV32-NEXT: srli a0, a0, 16
34+ ; RV32-NEXT: slli a1, a1, 16
35+ ; RV32-NEXT: or a0, a0, a1
2436; RV32-NEXT: ret
2537;
2638; RV64-LABEL: test_ashr_i48:
2739; RV64: # %bb.0:
28- ; RV64-NEXT: sraiw a0, a0, 16
40+ ; RV64-NEXT: slli a0, a0, 16
41+ ; RV64-NEXT: srai a0, a0, 16
42+ ; RV64-NEXT: srai a0, a0, 16
2943; RV64-NEXT: ret
3044 %ashr = ashr i48 %x , 16
3145 %trunc = trunc i48 %ashr to i16
@@ -40,7 +54,7 @@ define i16 @test_shl_i48(i48 %x) {
4054;
4155; RV64-LABEL: test_shl_i48:
4256; RV64: # %bb.0:
43- ; RV64-NEXT: slliw a0, a0, 8
57+ ; RV64-NEXT: slli a0, a0, 8
4458; RV64-NEXT: ret
4559 %shl = shl i48 %x , 8
4660 %trunc = trunc i48 %shl to i16
@@ -51,13 +65,34 @@ define i16 @test_lshr_i48_2(i48 %x, i48 %y) {
5165; RV32-LABEL: test_lshr_i48_2:
5266; RV32: # %bb.0:
5367; RV32-NEXT: andi a2, a2, 15
54- ; RV32-NEXT: srl a0, a0, a2
68+ ; RV32-NEXT: lui a3, 16
69+ ; RV32-NEXT: addi a3, a3, -1
70+ ; RV32-NEXT: li a4, 32
71+ ; RV32-NEXT: and a1, a1, a3
72+ ; RV32-NEXT: bltu a2, a4, .LBB3_2
73+ ; RV32-NEXT: # %bb.1:
74+ ; RV32-NEXT: addi a3, a2, -32
75+ ; RV32-NEXT: srl a1, a1, a3
76+ ; RV32-NEXT: bnez a2, .LBB3_3
77+ ; RV32-NEXT: j .LBB3_4
78+ ; RV32-NEXT: .LBB3_2:
79+ ; RV32-NEXT: srl a3, a0, a2
80+ ; RV32-NEXT: neg a4, a2
81+ ; RV32-NEXT: sll a1, a1, a4
82+ ; RV32-NEXT: or a1, a3, a1
83+ ; RV32-NEXT: beqz a2, .LBB3_4
84+ ; RV32-NEXT: .LBB3_3:
85+ ; RV32-NEXT: mv a0, a1
86+ ; RV32-NEXT: .LBB3_4:
5587; RV32-NEXT: ret
5688;
5789; RV64-LABEL: test_lshr_i48_2:
5890; RV64: # %bb.0:
5991; RV64-NEXT: andi a1, a1, 15
60- ; RV64-NEXT: srlw a0, a0, a1
92+ ; RV64-NEXT: li a2, -1
93+ ; RV64-NEXT: srli a2, a2, 16
94+ ; RV64-NEXT: and a0, a0, a2
95+ ; RV64-NEXT: srl a0, a0, a1
6196; RV64-NEXT: ret
6297 %and = and i48 %y , 15
6398 %lshr = lshr i48 %x , %and
@@ -69,13 +104,32 @@ define i16 @test_ashr_i48_2(i48 %x, i48 %y) {
69104; RV32-LABEL: test_ashr_i48_2:
70105; RV32: # %bb.0:
71106; RV32-NEXT: andi a2, a2, 15
72- ; RV32-NEXT: sra a0, a0, a2
107+ ; RV32-NEXT: slli a1, a1, 16
108+ ; RV32-NEXT: li a3, 32
109+ ; RV32-NEXT: srai a1, a1, 16
110+ ; RV32-NEXT: bltu a2, a3, .LBB4_2
111+ ; RV32-NEXT: # %bb.1:
112+ ; RV32-NEXT: addi a3, a2, -32
113+ ; RV32-NEXT: sra a1, a1, a3
114+ ; RV32-NEXT: bnez a2, .LBB4_3
115+ ; RV32-NEXT: j .LBB4_4
116+ ; RV32-NEXT: .LBB4_2:
117+ ; RV32-NEXT: srl a3, a0, a2
118+ ; RV32-NEXT: neg a4, a2
119+ ; RV32-NEXT: sll a1, a1, a4
120+ ; RV32-NEXT: or a1, a3, a1
121+ ; RV32-NEXT: beqz a2, .LBB4_4
122+ ; RV32-NEXT: .LBB4_3:
123+ ; RV32-NEXT: mv a0, a1
124+ ; RV32-NEXT: .LBB4_4:
73125; RV32-NEXT: ret
74126;
75127; RV64-LABEL: test_ashr_i48_2:
76128; RV64: # %bb.0:
77129; RV64-NEXT: andi a1, a1, 15
78- ; RV64-NEXT: sraw a0, a0, a1
130+ ; RV64-NEXT: slli a0, a0, 16
131+ ; RV64-NEXT: srai a0, a0, 16
132+ ; RV64-NEXT: sra a0, a0, a1
79133; RV64-NEXT: ret
80134 %and = and i48 %y , 15
81135 %ashr = ashr i48 %x , %and
@@ -87,13 +141,19 @@ define i16 @test_shl_i48_2(i48 %x, i48 %y) {
87141; RV32-LABEL: test_shl_i48_2:
88142; RV32: # %bb.0:
89143; RV32-NEXT: andi a2, a2, 15
144+ ; RV32-NEXT: li a1, 32
145+ ; RV32-NEXT: bltu a2, a1, .LBB5_2
146+ ; RV32-NEXT: # %bb.1:
147+ ; RV32-NEXT: li a0, 0
148+ ; RV32-NEXT: ret
149+ ; RV32-NEXT: .LBB5_2:
90150; RV32-NEXT: sll a0, a0, a2
91151; RV32-NEXT: ret
92152;
93153; RV64-LABEL: test_shl_i48_2:
94154; RV64: # %bb.0:
95155; RV64-NEXT: andi a1, a1, 15
96- ; RV64-NEXT: sllw a0, a0, a1
156+ ; RV64-NEXT: sll a0, a0, a1
97157; RV64-NEXT: ret
98158 %and = and i48 %y , 15
99159 %shl = shl i48 %x , %and
0 commit comments