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: sub 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: sub 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.ssub.sat.i32(i32 %x, i32 %a)
63 define i64 @func64(i64 %x, i64 %y, i64 %z) nounwind {
66 ; RV32-NEXT: mv a2, a1
67 ; RV32-NEXT: sltu a1, a0, a4
68 ; RV32-NEXT: sub a3, a2, a5
69 ; RV32-NEXT: sub a1, a3, a1
70 ; RV32-NEXT: xor a3, a2, a1
71 ; RV32-NEXT: xor a2, a2, a5
72 ; RV32-NEXT: and a2, a2, a3
73 ; RV32-NEXT: bltz a2, .LBB1_2
75 ; RV32-NEXT: sub a0, a0, a4
78 ; RV32-NEXT: srai a0, a1, 31
79 ; RV32-NEXT: lui a1, 524288
80 ; RV32-NEXT: xor a1, a0, a1
85 ; RV64-NEXT: mv a1, a0
86 ; RV64-NEXT: sgtz a3, a2
87 ; RV64-NEXT: sub a0, a0, a2
88 ; RV64-NEXT: slt a1, a0, a1
89 ; RV64-NEXT: beq a3, a1, .LBB1_2
91 ; RV64-NEXT: srai a0, a0, 63
92 ; RV64-NEXT: li a1, -1
93 ; RV64-NEXT: slli a1, a1, 63
94 ; RV64-NEXT: xor a0, a0, a1
98 %tmp = call i64 @llvm.ssub.sat.i64(i64 %x, i64 %z)
102 define i16 @func16(i16 %x, i16 %y, i16 %z) nounwind {
103 ; RV32I-LABEL: func16:
105 ; RV32I-NEXT: slli a0, a0, 16
106 ; RV32I-NEXT: srai a0, a0, 16
107 ; RV32I-NEXT: mul a1, a1, a2
108 ; RV32I-NEXT: slli a1, a1, 16
109 ; RV32I-NEXT: srai a1, a1, 16
110 ; RV32I-NEXT: sub a0, a0, a1
111 ; RV32I-NEXT: lui a1, 8
112 ; RV32I-NEXT: addi a1, a1, -1
113 ; RV32I-NEXT: bge a0, a1, .LBB2_3
114 ; RV32I-NEXT: # %bb.1:
115 ; RV32I-NEXT: lui a1, 1048568
116 ; RV32I-NEXT: bge a1, a0, .LBB2_4
117 ; RV32I-NEXT: .LBB2_2:
119 ; RV32I-NEXT: .LBB2_3:
120 ; RV32I-NEXT: mv a0, a1
121 ; RV32I-NEXT: lui a1, 1048568
122 ; RV32I-NEXT: blt a1, a0, .LBB2_2
123 ; RV32I-NEXT: .LBB2_4:
124 ; RV32I-NEXT: lui a0, 1048568
127 ; RV64I-LABEL: func16:
129 ; RV64I-NEXT: slli a0, a0, 48
130 ; RV64I-NEXT: srai a0, a0, 48
131 ; RV64I-NEXT: mul a1, a1, a2
132 ; RV64I-NEXT: slli a1, a1, 48
133 ; RV64I-NEXT: srai a1, a1, 48
134 ; RV64I-NEXT: sub a0, a0, a1
135 ; RV64I-NEXT: lui a1, 8
136 ; RV64I-NEXT: addiw a1, a1, -1
137 ; RV64I-NEXT: bge a0, a1, .LBB2_3
138 ; RV64I-NEXT: # %bb.1:
139 ; RV64I-NEXT: lui a1, 1048568
140 ; RV64I-NEXT: bge a1, a0, .LBB2_4
141 ; RV64I-NEXT: .LBB2_2:
143 ; RV64I-NEXT: .LBB2_3:
144 ; RV64I-NEXT: mv a0, a1
145 ; RV64I-NEXT: lui a1, 1048568
146 ; RV64I-NEXT: blt a1, a0, .LBB2_2
147 ; RV64I-NEXT: .LBB2_4:
148 ; RV64I-NEXT: lui a0, 1048568
151 ; RV32IZbb-LABEL: func16:
153 ; RV32IZbb-NEXT: sext.h a0, a0
154 ; RV32IZbb-NEXT: mul a1, a1, a2
155 ; RV32IZbb-NEXT: sext.h a1, a1
156 ; RV32IZbb-NEXT: sub a0, a0, a1
157 ; RV32IZbb-NEXT: lui a1, 8
158 ; RV32IZbb-NEXT: addi a1, a1, -1
159 ; RV32IZbb-NEXT: min a0, a0, a1
160 ; RV32IZbb-NEXT: lui a1, 1048568
161 ; RV32IZbb-NEXT: max a0, a0, a1
164 ; RV64IZbb-LABEL: func16:
166 ; RV64IZbb-NEXT: sext.h a0, a0
167 ; RV64IZbb-NEXT: mul a1, a1, a2
168 ; RV64IZbb-NEXT: sext.h a1, a1
169 ; RV64IZbb-NEXT: sub a0, a0, a1
170 ; RV64IZbb-NEXT: lui a1, 8
171 ; RV64IZbb-NEXT: addiw a1, a1, -1
172 ; RV64IZbb-NEXT: min a0, a0, a1
173 ; RV64IZbb-NEXT: lui a1, 1048568
174 ; RV64IZbb-NEXT: max a0, a0, a1
177 %tmp = call i16 @llvm.ssub.sat.i16(i16 %x, i16 %a)
181 define i8 @func8(i8 %x, i8 %y, i8 %z) nounwind {
182 ; RV32I-LABEL: func8:
184 ; RV32I-NEXT: slli a0, a0, 24
185 ; RV32I-NEXT: srai a0, a0, 24
186 ; RV32I-NEXT: mul a1, a1, a2
187 ; RV32I-NEXT: slli a1, a1, 24
188 ; RV32I-NEXT: srai a1, a1, 24
189 ; RV32I-NEXT: sub a0, a0, a1
190 ; RV32I-NEXT: li a1, 127
191 ; RV32I-NEXT: bge a0, a1, .LBB3_3
192 ; RV32I-NEXT: # %bb.1:
193 ; RV32I-NEXT: li a1, -128
194 ; RV32I-NEXT: bge a1, a0, .LBB3_4
195 ; RV32I-NEXT: .LBB3_2:
197 ; RV32I-NEXT: .LBB3_3:
198 ; RV32I-NEXT: li a0, 127
199 ; RV32I-NEXT: li a1, -128
200 ; RV32I-NEXT: blt a1, a0, .LBB3_2
201 ; RV32I-NEXT: .LBB3_4:
202 ; RV32I-NEXT: li a0, -128
205 ; RV64I-LABEL: func8:
207 ; RV64I-NEXT: slli a0, a0, 56
208 ; RV64I-NEXT: srai a0, a0, 56
209 ; RV64I-NEXT: mul a1, a1, a2
210 ; RV64I-NEXT: slli a1, a1, 56
211 ; RV64I-NEXT: srai a1, a1, 56
212 ; RV64I-NEXT: sub a0, a0, a1
213 ; RV64I-NEXT: li a1, 127
214 ; RV64I-NEXT: bge a0, a1, .LBB3_3
215 ; RV64I-NEXT: # %bb.1:
216 ; RV64I-NEXT: li a1, -128
217 ; RV64I-NEXT: bge a1, a0, .LBB3_4
218 ; RV64I-NEXT: .LBB3_2:
220 ; RV64I-NEXT: .LBB3_3:
221 ; RV64I-NEXT: li a0, 127
222 ; RV64I-NEXT: li a1, -128
223 ; RV64I-NEXT: blt a1, a0, .LBB3_2
224 ; RV64I-NEXT: .LBB3_4:
225 ; RV64I-NEXT: li a0, -128
228 ; RV32IZbb-LABEL: func8:
230 ; RV32IZbb-NEXT: sext.b a0, a0
231 ; RV32IZbb-NEXT: mul a1, a1, a2
232 ; RV32IZbb-NEXT: sext.b a1, a1
233 ; RV32IZbb-NEXT: sub a0, a0, a1
234 ; RV32IZbb-NEXT: li a1, 127
235 ; RV32IZbb-NEXT: min a0, a0, a1
236 ; RV32IZbb-NEXT: li a1, -128
237 ; RV32IZbb-NEXT: max a0, a0, a1
240 ; RV64IZbb-LABEL: func8:
242 ; RV64IZbb-NEXT: sext.b a0, a0
243 ; RV64IZbb-NEXT: mul a1, a1, a2
244 ; RV64IZbb-NEXT: sext.b a1, a1
245 ; RV64IZbb-NEXT: sub a0, a0, a1
246 ; RV64IZbb-NEXT: li a1, 127
247 ; RV64IZbb-NEXT: min a0, a0, a1
248 ; RV64IZbb-NEXT: li a1, -128
249 ; RV64IZbb-NEXT: max a0, a0, a1
252 %tmp = call i8 @llvm.ssub.sat.i8(i8 %x, i8 %a)
256 define i4 @func4(i4 %x, i4 %y, i4 %z) nounwind {
257 ; RV32I-LABEL: func4:
259 ; RV32I-NEXT: slli a0, a0, 28
260 ; RV32I-NEXT: srai a0, a0, 28
261 ; RV32I-NEXT: mul a1, a1, a2
262 ; RV32I-NEXT: slli a1, a1, 28
263 ; RV32I-NEXT: srai a1, a1, 28
264 ; RV32I-NEXT: sub a0, a0, a1
265 ; RV32I-NEXT: li a1, 7
266 ; RV32I-NEXT: bge a0, a1, .LBB4_3
267 ; RV32I-NEXT: # %bb.1:
268 ; RV32I-NEXT: li a1, -8
269 ; RV32I-NEXT: bge a1, a0, .LBB4_4
270 ; RV32I-NEXT: .LBB4_2:
272 ; RV32I-NEXT: .LBB4_3:
273 ; RV32I-NEXT: li a0, 7
274 ; RV32I-NEXT: li a1, -8
275 ; RV32I-NEXT: blt a1, a0, .LBB4_2
276 ; RV32I-NEXT: .LBB4_4:
277 ; RV32I-NEXT: li a0, -8
280 ; RV64I-LABEL: func4:
282 ; RV64I-NEXT: slli a0, a0, 60
283 ; RV64I-NEXT: srai a0, a0, 60
284 ; RV64I-NEXT: mul a1, a1, a2
285 ; RV64I-NEXT: slli a1, a1, 60
286 ; RV64I-NEXT: srai a1, a1, 60
287 ; RV64I-NEXT: sub a0, a0, a1
288 ; RV64I-NEXT: li a1, 7
289 ; RV64I-NEXT: bge a0, a1, .LBB4_3
290 ; RV64I-NEXT: # %bb.1:
291 ; RV64I-NEXT: li a1, -8
292 ; RV64I-NEXT: bge a1, a0, .LBB4_4
293 ; RV64I-NEXT: .LBB4_2:
295 ; RV64I-NEXT: .LBB4_3:
296 ; RV64I-NEXT: li a0, 7
297 ; RV64I-NEXT: li a1, -8
298 ; RV64I-NEXT: blt a1, a0, .LBB4_2
299 ; RV64I-NEXT: .LBB4_4:
300 ; RV64I-NEXT: li a0, -8
303 ; RV32IZbb-LABEL: func4:
305 ; RV32IZbb-NEXT: slli a0, a0, 28
306 ; RV32IZbb-NEXT: srai a0, a0, 28
307 ; RV32IZbb-NEXT: mul a1, a1, a2
308 ; RV32IZbb-NEXT: slli a1, a1, 28
309 ; RV32IZbb-NEXT: srai a1, a1, 28
310 ; RV32IZbb-NEXT: sub a0, a0, a1
311 ; RV32IZbb-NEXT: li a1, 7
312 ; RV32IZbb-NEXT: min a0, a0, a1
313 ; RV32IZbb-NEXT: li a1, -8
314 ; RV32IZbb-NEXT: max a0, a0, a1
317 ; RV64IZbb-LABEL: func4:
319 ; RV64IZbb-NEXT: slli a0, a0, 60
320 ; RV64IZbb-NEXT: srai a0, a0, 60
321 ; RV64IZbb-NEXT: mul a1, a1, a2
322 ; RV64IZbb-NEXT: slli a1, a1, 60
323 ; RV64IZbb-NEXT: srai a1, a1, 60
324 ; RV64IZbb-NEXT: sub a0, a0, a1
325 ; RV64IZbb-NEXT: li a1, 7
326 ; RV64IZbb-NEXT: min a0, a0, a1
327 ; RV64IZbb-NEXT: li a1, -8
328 ; RV64IZbb-NEXT: max a0, a0, a1
331 %tmp = call i4 @llvm.ssub.sat.i4(i4 %x, i4 %a)