1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
3 ; RUN: | FileCheck %s -check-prefix=RV32I
4 ; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
5 ; RUN: | FileCheck %s -check-prefix=RV64I
7 ; Basic shift support is tested as part of ALU.ll. This file ensures that
8 ; shifts which may not be supported natively are lowered properly.
10 define i64 @lshr64(i64 %a, i64 %b) nounwind {
11 ; RV32I-LABEL: lshr64:
13 ; RV32I-NEXT: addi a3, a2, -32
14 ; RV32I-NEXT: bltz a3, .LBB0_2
15 ; RV32I-NEXT: # %bb.1:
16 ; RV32I-NEXT: srl a0, a1, a3
17 ; RV32I-NEXT: mv a1, zero
19 ; RV32I-NEXT: .LBB0_2:
20 ; RV32I-NEXT: addi a3, zero, 31
21 ; RV32I-NEXT: sub a3, a3, a2
22 ; RV32I-NEXT: slli a4, a1, 1
23 ; RV32I-NEXT: sll a3, a4, a3
24 ; RV32I-NEXT: srl a0, a0, a2
25 ; RV32I-NEXT: or a0, a0, a3
26 ; RV32I-NEXT: srl a1, a1, a2
29 ; RV64I-LABEL: lshr64:
31 ; RV64I-NEXT: srl a0, a0, a1
37 define i64 @lshr64_minsize(i64 %a, i64 %b) minsize nounwind {
38 ; RV32I-LABEL: lshr64_minsize:
40 ; RV32I-NEXT: addi sp, sp, -16
41 ; RV32I-NEXT: sw ra, 12(sp)
42 ; RV32I-NEXT: call __lshrdi3
43 ; RV32I-NEXT: lw ra, 12(sp)
44 ; RV32I-NEXT: addi sp, sp, 16
47 ; RV64I-LABEL: lshr64_minsize:
49 ; RV64I-NEXT: srl a0, a0, a1
55 define i64 @ashr64(i64 %a, i64 %b) nounwind {
56 ; RV32I-LABEL: ashr64:
58 ; RV32I-NEXT: addi a3, a2, -32
59 ; RV32I-NEXT: bltz a3, .LBB2_2
60 ; RV32I-NEXT: # %bb.1:
61 ; RV32I-NEXT: sra a0, a1, a3
62 ; RV32I-NEXT: srai a1, a1, 31
64 ; RV32I-NEXT: .LBB2_2:
65 ; RV32I-NEXT: addi a3, zero, 31
66 ; RV32I-NEXT: sub a3, a3, a2
67 ; RV32I-NEXT: slli a4, a1, 1
68 ; RV32I-NEXT: sll a3, a4, a3
69 ; RV32I-NEXT: srl a0, a0, a2
70 ; RV32I-NEXT: or a0, a0, a3
71 ; RV32I-NEXT: sra a1, a1, a2
74 ; RV64I-LABEL: ashr64:
76 ; RV64I-NEXT: sra a0, a0, a1
82 define i64 @ashr64_minsize(i64 %a, i64 %b) minsize nounwind {
83 ; RV32I-LABEL: ashr64_minsize:
85 ; RV32I-NEXT: addi sp, sp, -16
86 ; RV32I-NEXT: sw ra, 12(sp)
87 ; RV32I-NEXT: call __ashrdi3
88 ; RV32I-NEXT: lw ra, 12(sp)
89 ; RV32I-NEXT: addi sp, sp, 16
92 ; RV64I-LABEL: ashr64_minsize:
94 ; RV64I-NEXT: sra a0, a0, a1
100 define i64 @shl64(i64 %a, i64 %b) nounwind {
101 ; RV32I-LABEL: shl64:
103 ; RV32I-NEXT: addi a3, a2, -32
104 ; RV32I-NEXT: bltz a3, .LBB4_2
105 ; RV32I-NEXT: # %bb.1:
106 ; RV32I-NEXT: sll a1, a0, a3
107 ; RV32I-NEXT: mv a0, zero
109 ; RV32I-NEXT: .LBB4_2:
110 ; RV32I-NEXT: addi a3, zero, 31
111 ; RV32I-NEXT: sub a3, a3, a2
112 ; RV32I-NEXT: srli a4, a0, 1
113 ; RV32I-NEXT: srl a3, a4, a3
114 ; RV32I-NEXT: sll a1, a1, a2
115 ; RV32I-NEXT: or a1, a1, a3
116 ; RV32I-NEXT: sll a0, a0, a2
119 ; RV64I-LABEL: shl64:
121 ; RV64I-NEXT: sll a0, a0, a1
127 define i64 @shl64_minsize(i64 %a, i64 %b) minsize nounwind {
128 ; RV32I-LABEL: shl64_minsize:
130 ; RV32I-NEXT: addi sp, sp, -16
131 ; RV32I-NEXT: sw ra, 12(sp)
132 ; RV32I-NEXT: call __ashldi3
133 ; RV32I-NEXT: lw ra, 12(sp)
134 ; RV32I-NEXT: addi sp, sp, 16
137 ; RV64I-LABEL: shl64_minsize:
139 ; RV64I-NEXT: sll a0, a0, a1
145 define i128 @lshr128(i128 %a, i128 %b) nounwind {
146 ; RV32I-LABEL: lshr128:
148 ; RV32I-NEXT: addi sp, sp, -48
149 ; RV32I-NEXT: sw ra, 44(sp)
150 ; RV32I-NEXT: sw s0, 40(sp)
151 ; RV32I-NEXT: mv s0, a0
152 ; RV32I-NEXT: lw a0, 12(a1)
153 ; RV32I-NEXT: sw a0, 20(sp)
154 ; RV32I-NEXT: lw a0, 8(a1)
155 ; RV32I-NEXT: sw a0, 16(sp)
156 ; RV32I-NEXT: lw a0, 4(a1)
157 ; RV32I-NEXT: sw a0, 12(sp)
158 ; RV32I-NEXT: lw a0, 0(a1)
159 ; RV32I-NEXT: sw a0, 8(sp)
160 ; RV32I-NEXT: lw a2, 0(a2)
161 ; RV32I-NEXT: addi a0, sp, 24
162 ; RV32I-NEXT: addi a1, sp, 8
163 ; RV32I-NEXT: call __lshrti3
164 ; RV32I-NEXT: lw a0, 36(sp)
165 ; RV32I-NEXT: sw a0, 12(s0)
166 ; RV32I-NEXT: lw a0, 32(sp)
167 ; RV32I-NEXT: sw a0, 8(s0)
168 ; RV32I-NEXT: lw a0, 28(sp)
169 ; RV32I-NEXT: sw a0, 4(s0)
170 ; RV32I-NEXT: lw a0, 24(sp)
171 ; RV32I-NEXT: sw a0, 0(s0)
172 ; RV32I-NEXT: lw s0, 40(sp)
173 ; RV32I-NEXT: lw ra, 44(sp)
174 ; RV32I-NEXT: addi sp, sp, 48
177 ; RV64I-LABEL: lshr128:
179 ; RV64I-NEXT: addi a3, a2, -64
180 ; RV64I-NEXT: bltz a3, .LBB6_2
181 ; RV64I-NEXT: # %bb.1:
182 ; RV64I-NEXT: srl a0, a1, a3
183 ; RV64I-NEXT: mv a1, zero
185 ; RV64I-NEXT: .LBB6_2:
186 ; RV64I-NEXT: addi a3, zero, 63
187 ; RV64I-NEXT: sub a3, a3, a2
188 ; RV64I-NEXT: slli a4, a1, 1
189 ; RV64I-NEXT: sll a3, a4, a3
190 ; RV64I-NEXT: srl a0, a0, a2
191 ; RV64I-NEXT: or a0, a0, a3
192 ; RV64I-NEXT: srl a1, a1, a2
194 %1 = lshr i128 %a, %b
198 define i128 @ashr128(i128 %a, i128 %b) nounwind {
199 ; RV32I-LABEL: ashr128:
201 ; RV32I-NEXT: addi sp, sp, -48
202 ; RV32I-NEXT: sw ra, 44(sp)
203 ; RV32I-NEXT: sw s0, 40(sp)
204 ; RV32I-NEXT: mv s0, a0
205 ; RV32I-NEXT: lw a0, 12(a1)
206 ; RV32I-NEXT: sw a0, 20(sp)
207 ; RV32I-NEXT: lw a0, 8(a1)
208 ; RV32I-NEXT: sw a0, 16(sp)
209 ; RV32I-NEXT: lw a0, 4(a1)
210 ; RV32I-NEXT: sw a0, 12(sp)
211 ; RV32I-NEXT: lw a0, 0(a1)
212 ; RV32I-NEXT: sw a0, 8(sp)
213 ; RV32I-NEXT: lw a2, 0(a2)
214 ; RV32I-NEXT: addi a0, sp, 24
215 ; RV32I-NEXT: addi a1, sp, 8
216 ; RV32I-NEXT: call __ashrti3
217 ; RV32I-NEXT: lw a0, 36(sp)
218 ; RV32I-NEXT: sw a0, 12(s0)
219 ; RV32I-NEXT: lw a0, 32(sp)
220 ; RV32I-NEXT: sw a0, 8(s0)
221 ; RV32I-NEXT: lw a0, 28(sp)
222 ; RV32I-NEXT: sw a0, 4(s0)
223 ; RV32I-NEXT: lw a0, 24(sp)
224 ; RV32I-NEXT: sw a0, 0(s0)
225 ; RV32I-NEXT: lw s0, 40(sp)
226 ; RV32I-NEXT: lw ra, 44(sp)
227 ; RV32I-NEXT: addi sp, sp, 48
230 ; RV64I-LABEL: ashr128:
232 ; RV64I-NEXT: addi a3, a2, -64
233 ; RV64I-NEXT: bltz a3, .LBB7_2
234 ; RV64I-NEXT: # %bb.1:
235 ; RV64I-NEXT: sra a0, a1, a3
236 ; RV64I-NEXT: srai a1, a1, 63
238 ; RV64I-NEXT: .LBB7_2:
239 ; RV64I-NEXT: addi a3, zero, 63
240 ; RV64I-NEXT: sub a3, a3, a2
241 ; RV64I-NEXT: slli a4, a1, 1
242 ; RV64I-NEXT: sll a3, a4, a3
243 ; RV64I-NEXT: srl a0, a0, a2
244 ; RV64I-NEXT: or a0, a0, a3
245 ; RV64I-NEXT: sra a1, a1, a2
247 %1 = ashr i128 %a, %b
251 define i128 @shl128(i128 %a, i128 %b) nounwind {
252 ; RV32I-LABEL: shl128:
254 ; RV32I-NEXT: addi sp, sp, -48
255 ; RV32I-NEXT: sw ra, 44(sp)
256 ; RV32I-NEXT: sw s0, 40(sp)
257 ; RV32I-NEXT: mv s0, a0
258 ; RV32I-NEXT: lw a0, 12(a1)
259 ; RV32I-NEXT: sw a0, 20(sp)
260 ; RV32I-NEXT: lw a0, 8(a1)
261 ; RV32I-NEXT: sw a0, 16(sp)
262 ; RV32I-NEXT: lw a0, 4(a1)
263 ; RV32I-NEXT: sw a0, 12(sp)
264 ; RV32I-NEXT: lw a0, 0(a1)
265 ; RV32I-NEXT: sw a0, 8(sp)
266 ; RV32I-NEXT: lw a2, 0(a2)
267 ; RV32I-NEXT: addi a0, sp, 24
268 ; RV32I-NEXT: addi a1, sp, 8
269 ; RV32I-NEXT: call __ashlti3
270 ; RV32I-NEXT: lw a0, 36(sp)
271 ; RV32I-NEXT: sw a0, 12(s0)
272 ; RV32I-NEXT: lw a0, 32(sp)
273 ; RV32I-NEXT: sw a0, 8(s0)
274 ; RV32I-NEXT: lw a0, 28(sp)
275 ; RV32I-NEXT: sw a0, 4(s0)
276 ; RV32I-NEXT: lw a0, 24(sp)
277 ; RV32I-NEXT: sw a0, 0(s0)
278 ; RV32I-NEXT: lw s0, 40(sp)
279 ; RV32I-NEXT: lw ra, 44(sp)
280 ; RV32I-NEXT: addi sp, sp, 48
283 ; RV64I-LABEL: shl128:
285 ; RV64I-NEXT: addi a3, a2, -64
286 ; RV64I-NEXT: bltz a3, .LBB8_2
287 ; RV64I-NEXT: # %bb.1:
288 ; RV64I-NEXT: sll a1, a0, a3
289 ; RV64I-NEXT: mv a0, zero
291 ; RV64I-NEXT: .LBB8_2:
292 ; RV64I-NEXT: addi a3, zero, 63
293 ; RV64I-NEXT: sub a3, a3, a2
294 ; RV64I-NEXT: srli a4, a0, 1
295 ; RV64I-NEXT: srl a3, a4, a3
296 ; RV64I-NEXT: sll a1, a1, a2
297 ; RV64I-NEXT: or a1, a1, a3
298 ; RV64I-NEXT: sll a0, a0, a2