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.ssub.sat.i4(i4, i4)
8 declare i8 @llvm.ssub.sat.i8(i8, i8)
9 declare i16 @llvm.ssub.sat.i16(i16, i16)
10 declare i32 @llvm.ssub.sat.i32(i32, i32)
11 declare i64 @llvm.ssub.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 a0, a1, a2
18 ; RV32-NEXT: sgtz a1, a0
19 ; RV32-NEXT: sub a0, a3, a0
20 ; RV32-NEXT: slt a2, a0, a3
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: subw a2, a0, a1
34 ; RV64I-NEXT: sub a0, a0, a1
35 ; RV64I-NEXT: beq a2, a0, .LBB0_2
36 ; RV64I-NEXT: # %bb.1:
37 ; RV64I-NEXT: sraiw a0, a0, 31
38 ; RV64I-NEXT: lui a1, 524288
39 ; RV64I-NEXT: xor a0, a0, a1
40 ; RV64I-NEXT: .LBB0_2:
43 ; RV64IZbb-LABEL: func32:
45 ; RV64IZbb-NEXT: sext.w a0, a0
46 ; RV64IZbb-NEXT: mulw a1, a1, a2
47 ; RV64IZbb-NEXT: sub a0, a0, a1
48 ; RV64IZbb-NEXT: lui a1, 524288
49 ; RV64IZbb-NEXT: addiw a2, a1, -1
50 ; RV64IZbb-NEXT: min a0, a0, a2
51 ; RV64IZbb-NEXT: max a0, a0, a1
54 %tmp = call i32 @llvm.ssub.sat.i32(i32 %x, i32 %a)
58 define i64 @func64(i64 %x, i64 %y, i64 %z) nounwind {
61 ; RV32-NEXT: mv a2, a1
62 ; RV32-NEXT: sltu a1, a0, a4
63 ; RV32-NEXT: sub a3, a2, a5
64 ; RV32-NEXT: sub a1, a3, a1
65 ; RV32-NEXT: xor a3, a2, a1
66 ; RV32-NEXT: xor a2, a2, a5
67 ; RV32-NEXT: and a2, a2, a3
68 ; RV32-NEXT: bltz a2, .LBB1_2
70 ; RV32-NEXT: sub a0, a0, a4
73 ; RV32-NEXT: srai a0, a1, 31
74 ; RV32-NEXT: lui a1, 524288
75 ; RV32-NEXT: xor a1, a0, a1
80 ; RV64-NEXT: mv a1, a0
81 ; RV64-NEXT: sgtz a3, a2
82 ; RV64-NEXT: sub a0, a0, a2
83 ; RV64-NEXT: slt a1, a0, a1
84 ; RV64-NEXT: beq a3, a1, .LBB1_2
86 ; RV64-NEXT: srai a0, a0, 63
87 ; RV64-NEXT: li a1, -1
88 ; RV64-NEXT: slli a1, a1, 63
89 ; RV64-NEXT: xor a0, a0, a1
93 %tmp = call i64 @llvm.ssub.sat.i64(i64 %x, i64 %z)
97 define i16 @func16(i16 %x, i16 %y, i16 %z) nounwind {
98 ; RV32I-LABEL: func16:
100 ; RV32I-NEXT: slli a0, a0, 16
101 ; RV32I-NEXT: srai a0, a0, 16
102 ; RV32I-NEXT: mul a1, a1, a2
103 ; RV32I-NEXT: slli a1, a1, 16
104 ; RV32I-NEXT: srai a1, a1, 16
105 ; RV32I-NEXT: sub a0, a0, a1
106 ; RV32I-NEXT: lui a1, 8
107 ; RV32I-NEXT: addi a1, a1, -1
108 ; RV32I-NEXT: bge a0, a1, .LBB2_3
109 ; RV32I-NEXT: # %bb.1:
110 ; RV32I-NEXT: lui a1, 1048568
111 ; RV32I-NEXT: bge a1, a0, .LBB2_4
112 ; RV32I-NEXT: .LBB2_2:
114 ; RV32I-NEXT: .LBB2_3:
115 ; RV32I-NEXT: mv a0, a1
116 ; RV32I-NEXT: lui a1, 1048568
117 ; RV32I-NEXT: blt a1, a0, .LBB2_2
118 ; RV32I-NEXT: .LBB2_4:
119 ; RV32I-NEXT: lui a0, 1048568
122 ; RV64I-LABEL: func16:
124 ; RV64I-NEXT: slli a0, a0, 48
125 ; RV64I-NEXT: srai a0, a0, 48
126 ; RV64I-NEXT: mul a1, a1, a2
127 ; RV64I-NEXT: slli a1, a1, 48
128 ; RV64I-NEXT: srai a1, a1, 48
129 ; RV64I-NEXT: sub a0, a0, a1
130 ; RV64I-NEXT: lui a1, 8
131 ; RV64I-NEXT: addiw a1, a1, -1
132 ; RV64I-NEXT: bge a0, a1, .LBB2_3
133 ; RV64I-NEXT: # %bb.1:
134 ; RV64I-NEXT: lui a1, 1048568
135 ; RV64I-NEXT: bge a1, a0, .LBB2_4
136 ; RV64I-NEXT: .LBB2_2:
138 ; RV64I-NEXT: .LBB2_3:
139 ; RV64I-NEXT: mv a0, a1
140 ; RV64I-NEXT: lui a1, 1048568
141 ; RV64I-NEXT: blt a1, a0, .LBB2_2
142 ; RV64I-NEXT: .LBB2_4:
143 ; RV64I-NEXT: lui a0, 1048568
146 ; RV32IZbb-LABEL: func16:
148 ; RV32IZbb-NEXT: sext.h a0, a0
149 ; RV32IZbb-NEXT: mul a1, a1, a2
150 ; RV32IZbb-NEXT: sext.h a1, a1
151 ; RV32IZbb-NEXT: sub a0, a0, a1
152 ; RV32IZbb-NEXT: lui a1, 8
153 ; RV32IZbb-NEXT: addi a1, a1, -1
154 ; RV32IZbb-NEXT: min a0, a0, a1
155 ; RV32IZbb-NEXT: lui a1, 1048568
156 ; RV32IZbb-NEXT: max a0, a0, a1
159 ; RV64IZbb-LABEL: func16:
161 ; RV64IZbb-NEXT: sext.h a0, a0
162 ; RV64IZbb-NEXT: mul a1, a1, a2
163 ; RV64IZbb-NEXT: sext.h a1, a1
164 ; RV64IZbb-NEXT: sub a0, a0, a1
165 ; RV64IZbb-NEXT: lui a1, 8
166 ; RV64IZbb-NEXT: addiw a1, a1, -1
167 ; RV64IZbb-NEXT: min a0, a0, a1
168 ; RV64IZbb-NEXT: lui a1, 1048568
169 ; RV64IZbb-NEXT: max a0, a0, a1
172 %tmp = call i16 @llvm.ssub.sat.i16(i16 %x, i16 %a)
176 define i8 @func8(i8 %x, i8 %y, i8 %z) nounwind {
177 ; RV32I-LABEL: func8:
179 ; RV32I-NEXT: slli a0, a0, 24
180 ; RV32I-NEXT: srai a0, a0, 24
181 ; RV32I-NEXT: mul a1, a1, a2
182 ; RV32I-NEXT: slli a1, a1, 24
183 ; RV32I-NEXT: srai a1, a1, 24
184 ; RV32I-NEXT: sub a0, a0, a1
185 ; RV32I-NEXT: li a1, 127
186 ; RV32I-NEXT: bge a0, a1, .LBB3_3
187 ; RV32I-NEXT: # %bb.1:
188 ; RV32I-NEXT: li a1, -128
189 ; RV32I-NEXT: bge a1, a0, .LBB3_4
190 ; RV32I-NEXT: .LBB3_2:
192 ; RV32I-NEXT: .LBB3_3:
193 ; RV32I-NEXT: li a0, 127
194 ; RV32I-NEXT: li a1, -128
195 ; RV32I-NEXT: blt a1, a0, .LBB3_2
196 ; RV32I-NEXT: .LBB3_4:
197 ; RV32I-NEXT: li a0, -128
200 ; RV64I-LABEL: func8:
202 ; RV64I-NEXT: slli a0, a0, 56
203 ; RV64I-NEXT: srai a0, a0, 56
204 ; RV64I-NEXT: mul a1, a1, a2
205 ; RV64I-NEXT: slli a1, a1, 56
206 ; RV64I-NEXT: srai a1, a1, 56
207 ; RV64I-NEXT: sub a0, a0, a1
208 ; RV64I-NEXT: li a1, 127
209 ; RV64I-NEXT: bge a0, a1, .LBB3_3
210 ; RV64I-NEXT: # %bb.1:
211 ; RV64I-NEXT: li a1, -128
212 ; RV64I-NEXT: bge a1, a0, .LBB3_4
213 ; RV64I-NEXT: .LBB3_2:
215 ; RV64I-NEXT: .LBB3_3:
216 ; RV64I-NEXT: li a0, 127
217 ; RV64I-NEXT: li a1, -128
218 ; RV64I-NEXT: blt a1, a0, .LBB3_2
219 ; RV64I-NEXT: .LBB3_4:
220 ; RV64I-NEXT: li a0, -128
223 ; RV32IZbb-LABEL: func8:
225 ; RV32IZbb-NEXT: sext.b a0, a0
226 ; RV32IZbb-NEXT: mul a1, a1, a2
227 ; RV32IZbb-NEXT: sext.b a1, a1
228 ; RV32IZbb-NEXT: sub a0, a0, a1
229 ; RV32IZbb-NEXT: li a1, 127
230 ; RV32IZbb-NEXT: min a0, a0, a1
231 ; RV32IZbb-NEXT: li a1, -128
232 ; RV32IZbb-NEXT: max a0, a0, a1
235 ; RV64IZbb-LABEL: func8:
237 ; RV64IZbb-NEXT: sext.b a0, a0
238 ; RV64IZbb-NEXT: mul a1, a1, a2
239 ; RV64IZbb-NEXT: sext.b a1, a1
240 ; RV64IZbb-NEXT: sub a0, a0, a1
241 ; RV64IZbb-NEXT: li a1, 127
242 ; RV64IZbb-NEXT: min a0, a0, a1
243 ; RV64IZbb-NEXT: li a1, -128
244 ; RV64IZbb-NEXT: max a0, a0, a1
247 %tmp = call i8 @llvm.ssub.sat.i8(i8 %x, i8 %a)
251 define i4 @func4(i4 %x, i4 %y, i4 %z) nounwind {
252 ; RV32I-LABEL: func4:
254 ; RV32I-NEXT: slli a0, a0, 28
255 ; RV32I-NEXT: srai a0, a0, 28
256 ; RV32I-NEXT: mul a1, a1, a2
257 ; RV32I-NEXT: slli a1, a1, 28
258 ; RV32I-NEXT: srai a1, a1, 28
259 ; RV32I-NEXT: sub a0, a0, a1
260 ; RV32I-NEXT: li a1, 7
261 ; RV32I-NEXT: bge a0, a1, .LBB4_3
262 ; RV32I-NEXT: # %bb.1:
263 ; RV32I-NEXT: li a1, -8
264 ; RV32I-NEXT: bge a1, a0, .LBB4_4
265 ; RV32I-NEXT: .LBB4_2:
267 ; RV32I-NEXT: .LBB4_3:
268 ; RV32I-NEXT: li a0, 7
269 ; RV32I-NEXT: li a1, -8
270 ; RV32I-NEXT: blt a1, a0, .LBB4_2
271 ; RV32I-NEXT: .LBB4_4:
272 ; RV32I-NEXT: li a0, -8
275 ; RV64I-LABEL: func4:
277 ; RV64I-NEXT: slli a0, a0, 60
278 ; RV64I-NEXT: srai a0, a0, 60
279 ; RV64I-NEXT: mul a1, a1, a2
280 ; RV64I-NEXT: slli a1, a1, 60
281 ; RV64I-NEXT: srai a1, a1, 60
282 ; RV64I-NEXT: sub a0, a0, a1
283 ; RV64I-NEXT: li a1, 7
284 ; RV64I-NEXT: bge a0, a1, .LBB4_3
285 ; RV64I-NEXT: # %bb.1:
286 ; RV64I-NEXT: li a1, -8
287 ; RV64I-NEXT: bge a1, a0, .LBB4_4
288 ; RV64I-NEXT: .LBB4_2:
290 ; RV64I-NEXT: .LBB4_3:
291 ; RV64I-NEXT: li a0, 7
292 ; RV64I-NEXT: li a1, -8
293 ; RV64I-NEXT: blt a1, a0, .LBB4_2
294 ; RV64I-NEXT: .LBB4_4:
295 ; RV64I-NEXT: li a0, -8
298 ; RV32IZbb-LABEL: func4:
300 ; RV32IZbb-NEXT: slli a0, a0, 28
301 ; RV32IZbb-NEXT: srai a0, a0, 28
302 ; RV32IZbb-NEXT: mul a1, a1, a2
303 ; RV32IZbb-NEXT: slli a1, a1, 28
304 ; RV32IZbb-NEXT: srai a1, a1, 28
305 ; RV32IZbb-NEXT: sub a0, a0, a1
306 ; RV32IZbb-NEXT: li a1, 7
307 ; RV32IZbb-NEXT: min a0, a0, a1
308 ; RV32IZbb-NEXT: li a1, -8
309 ; RV32IZbb-NEXT: max a0, a0, a1
312 ; RV64IZbb-LABEL: func4:
314 ; RV64IZbb-NEXT: slli a0, a0, 60
315 ; RV64IZbb-NEXT: srai a0, a0, 60
316 ; RV64IZbb-NEXT: mul a1, a1, a2
317 ; RV64IZbb-NEXT: slli a1, a1, 60
318 ; RV64IZbb-NEXT: srai a1, a1, 60
319 ; RV64IZbb-NEXT: sub a0, a0, a1
320 ; RV64IZbb-NEXT: li a1, 7
321 ; RV64IZbb-NEXT: min a0, a0, a1
322 ; RV64IZbb-NEXT: li a1, -8
323 ; RV64IZbb-NEXT: max a0, a0, a1
326 %tmp = call i4 @llvm.ssub.sat.i4(i4 %x, i4 %a)