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=RV32,RV32I
3 ; RUN: llc < %s -mtriple=riscv64 -mattr=+m | FileCheck %s --check-prefixes=RV64,RV64I
4 ; RUN: llc < %s -mtriple=riscv32 -mattr=+m,+zbb | FileCheck %s --check-prefixes=RV32,RV32IZbb
5 ; RUN: llc < %s -mtriple=riscv64 -mattr=+m,+zbb | FileCheck %s --check-prefixes=RV64,RV64IZbb
7 declare i4 @llvm.sadd.sat.i4(i4, i4)
8 declare i8 @llvm.sadd.sat.i8(i8, i8)
9 declare i16 @llvm.sadd.sat.i16(i16, i16)
10 declare i32 @llvm.sadd.sat.i32(i32, i32)
11 declare i64 @llvm.sadd.sat.i64(i64, i64)
13 define i32 @func32(i32 %x, i32 %y, i32 %z) nounwind {
16 ; RV32-NEXT: mv a3, a0
17 ; RV32-NEXT: mul a1, a1, a2
18 ; RV32-NEXT: add a0, a0, a1
19 ; RV32-NEXT: slt a2, a0, a3
20 ; RV32-NEXT: slti a1, a1, 0
21 ; RV32-NEXT: beq a1, a2, .LBB0_2
23 ; RV32-NEXT: srai a0, a0, 31
24 ; RV32-NEXT: lui a1, 524288
25 ; RV32-NEXT: xor a0, a0, a1
29 ; RV64I-LABEL: func32:
31 ; RV64I-NEXT: sext.w a0, a0
32 ; RV64I-NEXT: mulw a1, a1, a2
33 ; RV64I-NEXT: add a0, a0, a1
34 ; RV64I-NEXT: lui a1, 524288
35 ; RV64I-NEXT: addiw a2, a1, -1
36 ; RV64I-NEXT: bge a0, a2, .LBB0_3
37 ; RV64I-NEXT: # %bb.1:
38 ; RV64I-NEXT: bge a1, a0, .LBB0_4
39 ; RV64I-NEXT: .LBB0_2:
41 ; RV64I-NEXT: .LBB0_3:
42 ; RV64I-NEXT: mv a0, a2
43 ; RV64I-NEXT: blt a1, a2, .LBB0_2
44 ; RV64I-NEXT: .LBB0_4:
45 ; RV64I-NEXT: lui a0, 524288
48 ; RV64IZbb-LABEL: func32:
50 ; RV64IZbb-NEXT: sext.w a0, a0
51 ; RV64IZbb-NEXT: mulw a1, a1, a2
52 ; RV64IZbb-NEXT: add a0, a0, a1
53 ; RV64IZbb-NEXT: lui a1, 524288
54 ; RV64IZbb-NEXT: addiw a2, a1, -1
55 ; RV64IZbb-NEXT: min a0, a0, a2
56 ; RV64IZbb-NEXT: max a0, a0, a1
59 %tmp = call i32 @llvm.sadd.sat.i32(i32 %x, i32 %a)
63 define i64 @func64(i64 %x, i64 %y, i64 %z) nounwind {
64 ; RV32I-LABEL: func64:
66 ; RV32I-NEXT: mv a2, a1
67 ; RV32I-NEXT: mv a1, a0
68 ; RV32I-NEXT: add a3, a2, a5
69 ; RV32I-NEXT: add a0, a0, a4
70 ; RV32I-NEXT: sltu a1, a0, a1
71 ; RV32I-NEXT: add a1, a3, a1
72 ; RV32I-NEXT: xor a3, a2, a1
73 ; RV32I-NEXT: xor a2, a2, a5
74 ; RV32I-NEXT: not a2, a2
75 ; RV32I-NEXT: and a2, a2, a3
76 ; RV32I-NEXT: bgez a2, .LBB1_2
77 ; RV32I-NEXT: # %bb.1:
78 ; RV32I-NEXT: srai a0, a1, 31
79 ; RV32I-NEXT: lui a1, 524288
80 ; RV32I-NEXT: xor a1, a0, a1
81 ; RV32I-NEXT: .LBB1_2:
86 ; RV64-NEXT: mv a1, a0
87 ; RV64-NEXT: add a0, a0, a2
88 ; RV64-NEXT: slt a1, a0, a1
89 ; RV64-NEXT: slti a2, a2, 0
90 ; RV64-NEXT: beq a2, a1, .LBB1_2
92 ; RV64-NEXT: srai a0, a0, 63
93 ; RV64-NEXT: li a1, -1
94 ; RV64-NEXT: slli a1, a1, 63
95 ; RV64-NEXT: xor a0, a0, a1
99 ; RV32IZbb-LABEL: func64:
101 ; RV32IZbb-NEXT: mv a2, a1
102 ; RV32IZbb-NEXT: mv a1, a0
103 ; RV32IZbb-NEXT: add a3, a2, a5
104 ; RV32IZbb-NEXT: add a0, a0, a4
105 ; RV32IZbb-NEXT: sltu a1, a0, a1
106 ; RV32IZbb-NEXT: add a1, a3, a1
107 ; RV32IZbb-NEXT: xor a3, a2, a1
108 ; RV32IZbb-NEXT: xor a2, a2, a5
109 ; RV32IZbb-NEXT: andn a2, a3, a2
110 ; RV32IZbb-NEXT: bgez a2, .LBB1_2
111 ; RV32IZbb-NEXT: # %bb.1:
112 ; RV32IZbb-NEXT: srai a0, a1, 31
113 ; RV32IZbb-NEXT: lui a1, 524288
114 ; RV32IZbb-NEXT: xor a1, a0, a1
115 ; RV32IZbb-NEXT: .LBB1_2:
118 %tmp = call i64 @llvm.sadd.sat.i64(i64 %x, i64 %z)
122 define i16 @func16(i16 %x, i16 %y, i16 %z) nounwind {
123 ; RV32I-LABEL: func16:
125 ; RV32I-NEXT: slli a0, a0, 16
126 ; RV32I-NEXT: srai a0, a0, 16
127 ; RV32I-NEXT: mul a1, a1, a2
128 ; RV32I-NEXT: slli a1, a1, 16
129 ; RV32I-NEXT: srai a1, a1, 16
130 ; RV32I-NEXT: add a0, a0, a1
131 ; RV32I-NEXT: lui a1, 8
132 ; RV32I-NEXT: addi a1, a1, -1
133 ; RV32I-NEXT: bge a0, a1, .LBB2_3
134 ; RV32I-NEXT: # %bb.1:
135 ; RV32I-NEXT: lui a1, 1048568
136 ; RV32I-NEXT: bge a1, a0, .LBB2_4
137 ; RV32I-NEXT: .LBB2_2:
139 ; RV32I-NEXT: .LBB2_3:
140 ; RV32I-NEXT: mv a0, a1
141 ; RV32I-NEXT: lui a1, 1048568
142 ; RV32I-NEXT: blt a1, a0, .LBB2_2
143 ; RV32I-NEXT: .LBB2_4:
144 ; RV32I-NEXT: lui a0, 1048568
147 ; RV64I-LABEL: func16:
149 ; RV64I-NEXT: slli a0, a0, 48
150 ; RV64I-NEXT: srai a0, a0, 48
151 ; RV64I-NEXT: mul a1, a1, a2
152 ; RV64I-NEXT: slli a1, a1, 48
153 ; RV64I-NEXT: srai a1, a1, 48
154 ; RV64I-NEXT: add a0, a0, a1
155 ; RV64I-NEXT: lui a1, 8
156 ; RV64I-NEXT: addiw a1, a1, -1
157 ; RV64I-NEXT: bge a0, a1, .LBB2_3
158 ; RV64I-NEXT: # %bb.1:
159 ; RV64I-NEXT: lui a1, 1048568
160 ; RV64I-NEXT: bge a1, a0, .LBB2_4
161 ; RV64I-NEXT: .LBB2_2:
163 ; RV64I-NEXT: .LBB2_3:
164 ; RV64I-NEXT: mv a0, a1
165 ; RV64I-NEXT: lui a1, 1048568
166 ; RV64I-NEXT: blt a1, a0, .LBB2_2
167 ; RV64I-NEXT: .LBB2_4:
168 ; RV64I-NEXT: lui a0, 1048568
171 ; RV32IZbb-LABEL: func16:
173 ; RV32IZbb-NEXT: sext.h a0, a0
174 ; RV32IZbb-NEXT: mul a1, a1, a2
175 ; RV32IZbb-NEXT: sext.h a1, a1
176 ; RV32IZbb-NEXT: add a0, a0, a1
177 ; RV32IZbb-NEXT: lui a1, 8
178 ; RV32IZbb-NEXT: addi a1, a1, -1
179 ; RV32IZbb-NEXT: min a0, a0, a1
180 ; RV32IZbb-NEXT: lui a1, 1048568
181 ; RV32IZbb-NEXT: max a0, a0, a1
184 ; RV64IZbb-LABEL: func16:
186 ; RV64IZbb-NEXT: sext.h a0, a0
187 ; RV64IZbb-NEXT: mul a1, a1, a2
188 ; RV64IZbb-NEXT: sext.h a1, a1
189 ; RV64IZbb-NEXT: add a0, a0, a1
190 ; RV64IZbb-NEXT: lui a1, 8
191 ; RV64IZbb-NEXT: addiw a1, a1, -1
192 ; RV64IZbb-NEXT: min a0, a0, a1
193 ; RV64IZbb-NEXT: lui a1, 1048568
194 ; RV64IZbb-NEXT: max a0, a0, a1
197 %tmp = call i16 @llvm.sadd.sat.i16(i16 %x, i16 %a)
201 define i8 @func8(i8 %x, i8 %y, i8 %z) nounwind {
202 ; RV32I-LABEL: func8:
204 ; RV32I-NEXT: slli a0, a0, 24
205 ; RV32I-NEXT: srai a0, a0, 24
206 ; RV32I-NEXT: mul a1, a1, a2
207 ; RV32I-NEXT: slli a1, a1, 24
208 ; RV32I-NEXT: srai a1, a1, 24
209 ; RV32I-NEXT: add a0, a0, a1
210 ; RV32I-NEXT: li a1, 127
211 ; RV32I-NEXT: bge a0, a1, .LBB3_3
212 ; RV32I-NEXT: # %bb.1:
213 ; RV32I-NEXT: li a1, -128
214 ; RV32I-NEXT: bge a1, a0, .LBB3_4
215 ; RV32I-NEXT: .LBB3_2:
217 ; RV32I-NEXT: .LBB3_3:
218 ; RV32I-NEXT: li a0, 127
219 ; RV32I-NEXT: li a1, -128
220 ; RV32I-NEXT: blt a1, a0, .LBB3_2
221 ; RV32I-NEXT: .LBB3_4:
222 ; RV32I-NEXT: li a0, -128
225 ; RV64I-LABEL: func8:
227 ; RV64I-NEXT: slli a0, a0, 56
228 ; RV64I-NEXT: srai a0, a0, 56
229 ; RV64I-NEXT: mul a1, a1, a2
230 ; RV64I-NEXT: slli a1, a1, 56
231 ; RV64I-NEXT: srai a1, a1, 56
232 ; RV64I-NEXT: add a0, a0, a1
233 ; RV64I-NEXT: li a1, 127
234 ; RV64I-NEXT: bge a0, a1, .LBB3_3
235 ; RV64I-NEXT: # %bb.1:
236 ; RV64I-NEXT: li a1, -128
237 ; RV64I-NEXT: bge a1, a0, .LBB3_4
238 ; RV64I-NEXT: .LBB3_2:
240 ; RV64I-NEXT: .LBB3_3:
241 ; RV64I-NEXT: li a0, 127
242 ; RV64I-NEXT: li a1, -128
243 ; RV64I-NEXT: blt a1, a0, .LBB3_2
244 ; RV64I-NEXT: .LBB3_4:
245 ; RV64I-NEXT: li a0, -128
248 ; RV32IZbb-LABEL: func8:
250 ; RV32IZbb-NEXT: sext.b a0, a0
251 ; RV32IZbb-NEXT: mul a1, a1, a2
252 ; RV32IZbb-NEXT: sext.b a1, a1
253 ; RV32IZbb-NEXT: add a0, a0, a1
254 ; RV32IZbb-NEXT: li a1, 127
255 ; RV32IZbb-NEXT: min a0, a0, a1
256 ; RV32IZbb-NEXT: li a1, -128
257 ; RV32IZbb-NEXT: max a0, a0, a1
260 ; RV64IZbb-LABEL: func8:
262 ; RV64IZbb-NEXT: sext.b a0, a0
263 ; RV64IZbb-NEXT: mul a1, a1, a2
264 ; RV64IZbb-NEXT: sext.b a1, a1
265 ; RV64IZbb-NEXT: add a0, a0, a1
266 ; RV64IZbb-NEXT: li a1, 127
267 ; RV64IZbb-NEXT: min a0, a0, a1
268 ; RV64IZbb-NEXT: li a1, -128
269 ; RV64IZbb-NEXT: max a0, a0, a1
272 %tmp = call i8 @llvm.sadd.sat.i8(i8 %x, i8 %a)
276 define i4 @func4(i4 %x, i4 %y, i4 %z) nounwind {
277 ; RV32I-LABEL: func4:
279 ; RV32I-NEXT: slli a0, a0, 28
280 ; RV32I-NEXT: srai a0, a0, 28
281 ; RV32I-NEXT: mul a1, a1, a2
282 ; RV32I-NEXT: slli a1, a1, 28
283 ; RV32I-NEXT: srai a1, a1, 28
284 ; RV32I-NEXT: add a0, a0, a1
285 ; RV32I-NEXT: li a1, 7
286 ; RV32I-NEXT: bge a0, a1, .LBB4_3
287 ; RV32I-NEXT: # %bb.1:
288 ; RV32I-NEXT: li a1, -8
289 ; RV32I-NEXT: bge a1, a0, .LBB4_4
290 ; RV32I-NEXT: .LBB4_2:
292 ; RV32I-NEXT: .LBB4_3:
293 ; RV32I-NEXT: li a0, 7
294 ; RV32I-NEXT: li a1, -8
295 ; RV32I-NEXT: blt a1, a0, .LBB4_2
296 ; RV32I-NEXT: .LBB4_4:
297 ; RV32I-NEXT: li a0, -8
300 ; RV64I-LABEL: func4:
302 ; RV64I-NEXT: slli a0, a0, 60
303 ; RV64I-NEXT: srai a0, a0, 60
304 ; RV64I-NEXT: mul a1, a1, a2
305 ; RV64I-NEXT: slli a1, a1, 60
306 ; RV64I-NEXT: srai a1, a1, 60
307 ; RV64I-NEXT: add a0, a0, a1
308 ; RV64I-NEXT: li a1, 7
309 ; RV64I-NEXT: bge a0, a1, .LBB4_3
310 ; RV64I-NEXT: # %bb.1:
311 ; RV64I-NEXT: li a1, -8
312 ; RV64I-NEXT: bge a1, a0, .LBB4_4
313 ; RV64I-NEXT: .LBB4_2:
315 ; RV64I-NEXT: .LBB4_3:
316 ; RV64I-NEXT: li a0, 7
317 ; RV64I-NEXT: li a1, -8
318 ; RV64I-NEXT: blt a1, a0, .LBB4_2
319 ; RV64I-NEXT: .LBB4_4:
320 ; RV64I-NEXT: li a0, -8
323 ; RV32IZbb-LABEL: func4:
325 ; RV32IZbb-NEXT: slli a0, a0, 28
326 ; RV32IZbb-NEXT: srai a0, a0, 28
327 ; RV32IZbb-NEXT: mul a1, a1, a2
328 ; RV32IZbb-NEXT: slli a1, a1, 28
329 ; RV32IZbb-NEXT: srai a1, a1, 28
330 ; RV32IZbb-NEXT: add a0, a0, a1
331 ; RV32IZbb-NEXT: li a1, 7
332 ; RV32IZbb-NEXT: min a0, a0, a1
333 ; RV32IZbb-NEXT: li a1, -8
334 ; RV32IZbb-NEXT: max a0, a0, a1
337 ; RV64IZbb-LABEL: func4:
339 ; RV64IZbb-NEXT: slli a0, a0, 60
340 ; RV64IZbb-NEXT: srai a0, a0, 60
341 ; RV64IZbb-NEXT: mul a1, a1, a2
342 ; RV64IZbb-NEXT: slli a1, a1, 60
343 ; RV64IZbb-NEXT: srai a1, a1, 60
344 ; RV64IZbb-NEXT: add a0, a0, a1
345 ; RV64IZbb-NEXT: li a1, 7
346 ; RV64IZbb-NEXT: min a0, a0, a1
347 ; RV64IZbb-NEXT: li a1, -8
348 ; RV64IZbb-NEXT: max a0, a0, a1
351 %tmp = call i4 @llvm.sadd.sat.i4(i4 %x, i4 %a)