1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=riscv32 -mattr=+m | FileCheck %s --check-prefixes=RV32NoZbt,RV32I
3 ; RUN: llc < %s -mtriple=riscv64 -mattr=+m | FileCheck %s --check-prefixes=RV64NoZbt,RV64I
4 ; RUN: llc < %s -mtriple=riscv32 -mattr=+m,+zbb | FileCheck %s --check-prefixes=RV32NoZbt,RV32IZbb
5 ; RUN: llc < %s -mtriple=riscv64 -mattr=+m,+zbb | FileCheck %s --check-prefixes=RV64NoZbt,RV64IZbb
6 ; RUN: llc < %s -mtriple=riscv32 -mattr=+m,+zbb,+experimental-zbt | FileCheck %s --check-prefixes=RV32IZbb,RV32IZbbZbt
7 ; RUN: llc < %s -mtriple=riscv64 -mattr=+m,+zbb,+experimental-zbt | FileCheck %s --check-prefixes=RV64IZbb,RV64IZbbZbt
9 declare i4 @llvm.ssub.sat.i4(i4, i4)
10 declare i8 @llvm.ssub.sat.i8(i8, i8)
11 declare i16 @llvm.ssub.sat.i16(i16, i16)
12 declare i32 @llvm.ssub.sat.i32(i32, i32)
13 declare i64 @llvm.ssub.sat.i64(i64, i64)
15 define i32 @func32(i32 %x, i32 %y, i32 %z) nounwind {
16 ; RV32NoZbt-LABEL: func32:
18 ; RV32NoZbt-NEXT: mv a3, a0
19 ; RV32NoZbt-NEXT: mul a0, a1, a2
20 ; RV32NoZbt-NEXT: sgtz a1, a0
21 ; RV32NoZbt-NEXT: sub a0, a3, a0
22 ; RV32NoZbt-NEXT: slt a2, a0, a3
23 ; RV32NoZbt-NEXT: beq a1, a2, .LBB0_2
24 ; RV32NoZbt-NEXT: # %bb.1:
25 ; RV32NoZbt-NEXT: srai a0, a0, 31
26 ; RV32NoZbt-NEXT: lui a1, 524288
27 ; RV32NoZbt-NEXT: xor a0, a0, a1
28 ; RV32NoZbt-NEXT: .LBB0_2:
31 ; RV64I-LABEL: func32:
33 ; RV64I-NEXT: sext.w a0, a0
34 ; RV64I-NEXT: mulw a1, a1, a2
35 ; RV64I-NEXT: sub a0, a0, a1
36 ; RV64I-NEXT: lui a1, 524288
37 ; RV64I-NEXT: addiw a2, a1, -1
38 ; RV64I-NEXT: bge a0, a2, .LBB0_3
39 ; RV64I-NEXT: # %bb.1:
40 ; RV64I-NEXT: bge a1, a0, .LBB0_4
41 ; RV64I-NEXT: .LBB0_2:
43 ; RV64I-NEXT: .LBB0_3:
44 ; RV64I-NEXT: mv a0, a2
45 ; RV64I-NEXT: blt a1, a0, .LBB0_2
46 ; RV64I-NEXT: .LBB0_4:
47 ; RV64I-NEXT: lui a0, 524288
50 ; RV64IZbb-LABEL: func32:
52 ; RV64IZbb-NEXT: sext.w a0, a0
53 ; RV64IZbb-NEXT: mulw a1, a1, a2
54 ; RV64IZbb-NEXT: sub a0, a0, a1
55 ; RV64IZbb-NEXT: lui a1, 524288
56 ; RV64IZbb-NEXT: addiw a2, a1, -1
57 ; RV64IZbb-NEXT: min a0, a0, a2
58 ; RV64IZbb-NEXT: max a0, a0, a1
61 ; RV32IZbbZbt-LABEL: func32:
62 ; RV32IZbbZbt: # %bb.0:
63 ; RV32IZbbZbt-NEXT: mul a1, a1, a2
64 ; RV32IZbbZbt-NEXT: sgtz a2, a1
65 ; RV32IZbbZbt-NEXT: sub a1, a0, a1
66 ; RV32IZbbZbt-NEXT: slt a0, a1, a0
67 ; RV32IZbbZbt-NEXT: xor a0, a2, a0
68 ; RV32IZbbZbt-NEXT: srai a2, a1, 31
69 ; RV32IZbbZbt-NEXT: lui a3, 524288
70 ; RV32IZbbZbt-NEXT: xor a2, a2, a3
71 ; RV32IZbbZbt-NEXT: cmov a0, a0, a2, a1
72 ; RV32IZbbZbt-NEXT: ret
74 %tmp = call i32 @llvm.ssub.sat.i32(i32 %x, i32 %a)
78 define i64 @func64(i64 %x, i64 %y, i64 %z) nounwind {
79 ; RV32NoZbt-LABEL: func64:
81 ; RV32NoZbt-NEXT: mv a2, a1
82 ; RV32NoZbt-NEXT: sltu a1, a0, a4
83 ; RV32NoZbt-NEXT: sub a3, a2, a5
84 ; RV32NoZbt-NEXT: sub a1, a3, a1
85 ; RV32NoZbt-NEXT: xor a3, a2, a1
86 ; RV32NoZbt-NEXT: xor a2, a2, a5
87 ; RV32NoZbt-NEXT: and a2, a2, a3
88 ; RV32NoZbt-NEXT: bltz a2, .LBB1_2
89 ; RV32NoZbt-NEXT: # %bb.1:
90 ; RV32NoZbt-NEXT: sub a0, a0, a4
92 ; RV32NoZbt-NEXT: .LBB1_2:
93 ; RV32NoZbt-NEXT: srai a0, a1, 31
94 ; RV32NoZbt-NEXT: lui a1, 524288
95 ; RV32NoZbt-NEXT: xor a1, a0, a1
98 ; RV64NoZbt-LABEL: func64:
100 ; RV64NoZbt-NEXT: mv a1, a0
101 ; RV64NoZbt-NEXT: sgtz a3, a2
102 ; RV64NoZbt-NEXT: sub a0, a0, a2
103 ; RV64NoZbt-NEXT: slt a1, a0, a1
104 ; RV64NoZbt-NEXT: beq a3, a1, .LBB1_2
105 ; RV64NoZbt-NEXT: # %bb.1:
106 ; RV64NoZbt-NEXT: srai a0, a0, 63
107 ; RV64NoZbt-NEXT: li a1, -1
108 ; RV64NoZbt-NEXT: slli a1, a1, 63
109 ; RV64NoZbt-NEXT: xor a0, a0, a1
110 ; RV64NoZbt-NEXT: .LBB1_2:
111 ; RV64NoZbt-NEXT: ret
113 ; RV32IZbbZbt-LABEL: func64:
114 ; RV32IZbbZbt: # %bb.0:
115 ; RV32IZbbZbt-NEXT: sltu a2, a0, a4
116 ; RV32IZbbZbt-NEXT: sub a3, a1, a5
117 ; RV32IZbbZbt-NEXT: sub a2, a3, a2
118 ; RV32IZbbZbt-NEXT: srai a3, a2, 31
119 ; RV32IZbbZbt-NEXT: lui a6, 524288
120 ; RV32IZbbZbt-NEXT: xor a6, a3, a6
121 ; RV32IZbbZbt-NEXT: xor a7, a1, a2
122 ; RV32IZbbZbt-NEXT: xor a1, a1, a5
123 ; RV32IZbbZbt-NEXT: and a1, a1, a7
124 ; RV32IZbbZbt-NEXT: slti a5, a1, 0
125 ; RV32IZbbZbt-NEXT: cmov a1, a5, a6, a2
126 ; RV32IZbbZbt-NEXT: sub a0, a0, a4
127 ; RV32IZbbZbt-NEXT: cmov a0, a5, a3, a0
128 ; RV32IZbbZbt-NEXT: ret
130 ; RV64IZbbZbt-LABEL: func64:
131 ; RV64IZbbZbt: # %bb.0:
132 ; RV64IZbbZbt-NEXT: sgtz a1, a2
133 ; RV64IZbbZbt-NEXT: sub a2, a0, a2
134 ; RV64IZbbZbt-NEXT: slt a0, a2, a0
135 ; RV64IZbbZbt-NEXT: xor a0, a1, a0
136 ; RV64IZbbZbt-NEXT: srai a1, a2, 63
137 ; RV64IZbbZbt-NEXT: li a3, -1
138 ; RV64IZbbZbt-NEXT: slli a3, a3, 63
139 ; RV64IZbbZbt-NEXT: xor a1, a1, a3
140 ; RV64IZbbZbt-NEXT: cmov a0, a0, a1, a2
141 ; RV64IZbbZbt-NEXT: ret
143 %tmp = call i64 @llvm.ssub.sat.i64(i64 %x, i64 %z)
147 define i16 @func16(i16 %x, i16 %y, i16 %z) nounwind {
148 ; RV32I-LABEL: func16:
150 ; RV32I-NEXT: slli a0, a0, 16
151 ; RV32I-NEXT: srai a0, a0, 16
152 ; RV32I-NEXT: mul a1, a1, a2
153 ; RV32I-NEXT: slli a1, a1, 16
154 ; RV32I-NEXT: srai a1, a1, 16
155 ; RV32I-NEXT: sub a0, a0, a1
156 ; RV32I-NEXT: lui a1, 8
157 ; RV32I-NEXT: addi a1, a1, -1
158 ; RV32I-NEXT: bge a0, a1, .LBB2_3
159 ; RV32I-NEXT: # %bb.1:
160 ; RV32I-NEXT: lui a1, 1048568
161 ; RV32I-NEXT: bge a1, a0, .LBB2_4
162 ; RV32I-NEXT: .LBB2_2:
164 ; RV32I-NEXT: .LBB2_3:
165 ; RV32I-NEXT: mv a0, a1
166 ; RV32I-NEXT: lui a1, 1048568
167 ; RV32I-NEXT: blt a1, a0, .LBB2_2
168 ; RV32I-NEXT: .LBB2_4:
169 ; RV32I-NEXT: lui a0, 1048568
172 ; RV64I-LABEL: func16:
174 ; RV64I-NEXT: slli a0, a0, 48
175 ; RV64I-NEXT: srai a0, a0, 48
176 ; RV64I-NEXT: mulw a1, a1, a2
177 ; RV64I-NEXT: slli a1, a1, 48
178 ; RV64I-NEXT: srai a1, a1, 48
179 ; RV64I-NEXT: sub a0, a0, a1
180 ; RV64I-NEXT: lui a1, 8
181 ; RV64I-NEXT: addiw a1, a1, -1
182 ; RV64I-NEXT: bge a0, a1, .LBB2_3
183 ; RV64I-NEXT: # %bb.1:
184 ; RV64I-NEXT: lui a1, 1048568
185 ; RV64I-NEXT: bge a1, a0, .LBB2_4
186 ; RV64I-NEXT: .LBB2_2:
188 ; RV64I-NEXT: .LBB2_3:
189 ; RV64I-NEXT: mv a0, a1
190 ; RV64I-NEXT: lui a1, 1048568
191 ; RV64I-NEXT: blt a1, a0, .LBB2_2
192 ; RV64I-NEXT: .LBB2_4:
193 ; RV64I-NEXT: lui a0, 1048568
196 ; RV32IZbb-LABEL: func16:
198 ; RV32IZbb-NEXT: sext.h a0, a0
199 ; RV32IZbb-NEXT: mul a1, a1, a2
200 ; RV32IZbb-NEXT: sext.h a1, a1
201 ; RV32IZbb-NEXT: sub a0, a0, a1
202 ; RV32IZbb-NEXT: lui a1, 8
203 ; RV32IZbb-NEXT: addi a1, a1, -1
204 ; RV32IZbb-NEXT: min a0, a0, a1
205 ; RV32IZbb-NEXT: lui a1, 1048568
206 ; RV32IZbb-NEXT: max a0, a0, a1
209 ; RV64IZbb-LABEL: func16:
211 ; RV64IZbb-NEXT: sext.h a0, a0
212 ; RV64IZbb-NEXT: mulw a1, a1, a2
213 ; RV64IZbb-NEXT: sext.h a1, a1
214 ; RV64IZbb-NEXT: sub a0, a0, a1
215 ; RV64IZbb-NEXT: lui a1, 8
216 ; RV64IZbb-NEXT: addiw a1, a1, -1
217 ; RV64IZbb-NEXT: min a0, a0, a1
218 ; RV64IZbb-NEXT: lui a1, 1048568
219 ; RV64IZbb-NEXT: max a0, a0, a1
222 %tmp = call i16 @llvm.ssub.sat.i16(i16 %x, i16 %a)
226 define i8 @func8(i8 %x, i8 %y, i8 %z) nounwind {
227 ; RV32I-LABEL: func8:
229 ; RV32I-NEXT: slli a0, a0, 24
230 ; RV32I-NEXT: srai a0, a0, 24
231 ; RV32I-NEXT: mul a1, a1, a2
232 ; RV32I-NEXT: slli a1, a1, 24
233 ; RV32I-NEXT: srai a1, a1, 24
234 ; RV32I-NEXT: sub a0, a0, a1
235 ; RV32I-NEXT: li a1, 127
236 ; RV32I-NEXT: bge a0, a1, .LBB3_3
237 ; RV32I-NEXT: # %bb.1:
238 ; RV32I-NEXT: li a1, -128
239 ; RV32I-NEXT: bge a1, a0, .LBB3_4
240 ; RV32I-NEXT: .LBB3_2:
242 ; RV32I-NEXT: .LBB3_3:
243 ; RV32I-NEXT: li a0, 127
244 ; RV32I-NEXT: li a1, -128
245 ; RV32I-NEXT: blt a1, a0, .LBB3_2
246 ; RV32I-NEXT: .LBB3_4:
247 ; RV32I-NEXT: li a0, -128
250 ; RV64I-LABEL: func8:
252 ; RV64I-NEXT: slli a0, a0, 56
253 ; RV64I-NEXT: srai a0, a0, 56
254 ; RV64I-NEXT: mulw a1, a1, a2
255 ; RV64I-NEXT: slli a1, a1, 56
256 ; RV64I-NEXT: srai a1, a1, 56
257 ; RV64I-NEXT: sub a0, a0, a1
258 ; RV64I-NEXT: li a1, 127
259 ; RV64I-NEXT: bge a0, a1, .LBB3_3
260 ; RV64I-NEXT: # %bb.1:
261 ; RV64I-NEXT: li a1, -128
262 ; RV64I-NEXT: bge a1, a0, .LBB3_4
263 ; RV64I-NEXT: .LBB3_2:
265 ; RV64I-NEXT: .LBB3_3:
266 ; RV64I-NEXT: li a0, 127
267 ; RV64I-NEXT: li a1, -128
268 ; RV64I-NEXT: blt a1, a0, .LBB3_2
269 ; RV64I-NEXT: .LBB3_4:
270 ; RV64I-NEXT: li a0, -128
273 ; RV32IZbb-LABEL: func8:
275 ; RV32IZbb-NEXT: sext.b a0, a0
276 ; RV32IZbb-NEXT: mul a1, a1, a2
277 ; RV32IZbb-NEXT: sext.b a1, a1
278 ; RV32IZbb-NEXT: sub a0, a0, a1
279 ; RV32IZbb-NEXT: li a1, 127
280 ; RV32IZbb-NEXT: min a0, a0, a1
281 ; RV32IZbb-NEXT: li a1, -128
282 ; RV32IZbb-NEXT: max a0, a0, a1
285 ; RV64IZbb-LABEL: func8:
287 ; RV64IZbb-NEXT: sext.b a0, a0
288 ; RV64IZbb-NEXT: mulw a1, a1, a2
289 ; RV64IZbb-NEXT: sext.b a1, a1
290 ; RV64IZbb-NEXT: sub a0, a0, a1
291 ; RV64IZbb-NEXT: li a1, 127
292 ; RV64IZbb-NEXT: min a0, a0, a1
293 ; RV64IZbb-NEXT: li a1, -128
294 ; RV64IZbb-NEXT: max a0, a0, a1
297 %tmp = call i8 @llvm.ssub.sat.i8(i8 %x, i8 %a)
301 define i4 @func4(i4 %x, i4 %y, i4 %z) nounwind {
302 ; RV32I-LABEL: func4:
304 ; RV32I-NEXT: slli a0, a0, 28
305 ; RV32I-NEXT: srai a0, a0, 28
306 ; RV32I-NEXT: mul a1, a1, a2
307 ; RV32I-NEXT: slli a1, a1, 28
308 ; RV32I-NEXT: srai a1, a1, 28
309 ; RV32I-NEXT: sub a0, a0, a1
310 ; RV32I-NEXT: li a1, 7
311 ; RV32I-NEXT: bge a0, a1, .LBB4_3
312 ; RV32I-NEXT: # %bb.1:
313 ; RV32I-NEXT: li a1, -8
314 ; RV32I-NEXT: bge a1, a0, .LBB4_4
315 ; RV32I-NEXT: .LBB4_2:
317 ; RV32I-NEXT: .LBB4_3:
318 ; RV32I-NEXT: li a0, 7
319 ; RV32I-NEXT: li a1, -8
320 ; RV32I-NEXT: blt a1, a0, .LBB4_2
321 ; RV32I-NEXT: .LBB4_4:
322 ; RV32I-NEXT: li a0, -8
325 ; RV64I-LABEL: func4:
327 ; RV64I-NEXT: slli a0, a0, 60
328 ; RV64I-NEXT: srai a0, a0, 60
329 ; RV64I-NEXT: mulw a1, a1, a2
330 ; RV64I-NEXT: slli a1, a1, 60
331 ; RV64I-NEXT: srai a1, a1, 60
332 ; RV64I-NEXT: sub a0, a0, a1
333 ; RV64I-NEXT: li a1, 7
334 ; RV64I-NEXT: bge a0, a1, .LBB4_3
335 ; RV64I-NEXT: # %bb.1:
336 ; RV64I-NEXT: li a1, -8
337 ; RV64I-NEXT: bge a1, a0, .LBB4_4
338 ; RV64I-NEXT: .LBB4_2:
340 ; RV64I-NEXT: .LBB4_3:
341 ; RV64I-NEXT: li a0, 7
342 ; RV64I-NEXT: li a1, -8
343 ; RV64I-NEXT: blt a1, a0, .LBB4_2
344 ; RV64I-NEXT: .LBB4_4:
345 ; RV64I-NEXT: li a0, -8
348 ; RV32IZbb-LABEL: func4:
350 ; RV32IZbb-NEXT: slli a0, a0, 28
351 ; RV32IZbb-NEXT: srai a0, a0, 28
352 ; RV32IZbb-NEXT: mul a1, a1, a2
353 ; RV32IZbb-NEXT: slli a1, a1, 28
354 ; RV32IZbb-NEXT: srai a1, a1, 28
355 ; RV32IZbb-NEXT: sub a0, a0, a1
356 ; RV32IZbb-NEXT: li a1, 7
357 ; RV32IZbb-NEXT: min a0, a0, a1
358 ; RV32IZbb-NEXT: li a1, -8
359 ; RV32IZbb-NEXT: max a0, a0, a1
362 ; RV64IZbb-LABEL: func4:
364 ; RV64IZbb-NEXT: slli a0, a0, 60
365 ; RV64IZbb-NEXT: srai a0, a0, 60
366 ; RV64IZbb-NEXT: mulw a1, a1, a2
367 ; RV64IZbb-NEXT: slli a1, a1, 60
368 ; RV64IZbb-NEXT: srai a1, a1, 60
369 ; RV64IZbb-NEXT: sub a0, a0, a1
370 ; RV64IZbb-NEXT: li a1, 7
371 ; RV64IZbb-NEXT: min a0, a0, a1
372 ; RV64IZbb-NEXT: li a1, -8
373 ; RV64IZbb-NEXT: max a0, a0, a1
376 %tmp = call i4 @llvm.ssub.sat.i4(i4 %x, i4 %a)