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 signext i32 @func(i32 signext %x, i32 signext %y) nounwind {
16 ; RV32-NEXT: mv a2, a0
17 ; RV32-NEXT: add a0, a0, a1
18 ; RV32-NEXT: slt a2, a0, a2
19 ; RV32-NEXT: slti a1, a1, 0
20 ; RV32-NEXT: beq a1, a2, .LBB0_2
22 ; RV32-NEXT: srai a0, a0, 31
23 ; RV32-NEXT: lui a1, 524288
24 ; RV32-NEXT: xor a0, a0, a1
30 ; RV64I-NEXT: add a0, a0, a1
31 ; RV64I-NEXT: lui a1, 524288
32 ; RV64I-NEXT: addiw a2, a1, -1
33 ; RV64I-NEXT: bge a0, a2, .LBB0_3
34 ; RV64I-NEXT: # %bb.1:
35 ; RV64I-NEXT: bge a1, a0, .LBB0_4
36 ; RV64I-NEXT: .LBB0_2:
38 ; RV64I-NEXT: .LBB0_3:
39 ; RV64I-NEXT: mv a0, a2
40 ; RV64I-NEXT: blt a1, a2, .LBB0_2
41 ; RV64I-NEXT: .LBB0_4:
42 ; RV64I-NEXT: lui a0, 524288
45 ; RV64IZbb-LABEL: func:
47 ; RV64IZbb-NEXT: add 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
53 %tmp = call i32 @llvm.sadd.sat.i32(i32 %x, i32 %y);
57 define i64 @func2(i64 %x, i64 %y) nounwind {
60 ; RV32I-NEXT: mv a4, a1
61 ; RV32I-NEXT: mv a1, a0
62 ; RV32I-NEXT: add a5, a4, a3
63 ; RV32I-NEXT: add a0, a0, a2
64 ; RV32I-NEXT: sltu a1, a0, a1
65 ; RV32I-NEXT: add a1, a5, a1
66 ; RV32I-NEXT: xor a2, a4, a1
67 ; RV32I-NEXT: xor a3, a4, a3
68 ; RV32I-NEXT: not a3, a3
69 ; RV32I-NEXT: and a2, a3, a2
70 ; RV32I-NEXT: bgez a2, .LBB1_2
71 ; RV32I-NEXT: # %bb.1:
72 ; RV32I-NEXT: srai a0, a1, 31
73 ; RV32I-NEXT: lui a1, 524288
74 ; RV32I-NEXT: xor a1, a0, a1
75 ; RV32I-NEXT: .LBB1_2:
80 ; RV64-NEXT: mv a2, a0
81 ; RV64-NEXT: add a0, a0, a1
82 ; RV64-NEXT: slt a2, a0, a2
83 ; RV64-NEXT: slti a1, a1, 0
84 ; RV64-NEXT: beq a1, a2, .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 ; RV32IZbb-LABEL: func2:
95 ; RV32IZbb-NEXT: mv a4, a1
96 ; RV32IZbb-NEXT: mv a1, a0
97 ; RV32IZbb-NEXT: add a5, a4, a3
98 ; RV32IZbb-NEXT: add a0, a0, a2
99 ; RV32IZbb-NEXT: sltu a1, a0, a1
100 ; RV32IZbb-NEXT: add a1, a5, a1
101 ; RV32IZbb-NEXT: xor a2, a4, a1
102 ; RV32IZbb-NEXT: xor a3, a4, a3
103 ; RV32IZbb-NEXT: andn a2, a2, a3
104 ; RV32IZbb-NEXT: bgez a2, .LBB1_2
105 ; RV32IZbb-NEXT: # %bb.1:
106 ; RV32IZbb-NEXT: srai a0, a1, 31
107 ; RV32IZbb-NEXT: lui a1, 524288
108 ; RV32IZbb-NEXT: xor a1, a0, a1
109 ; RV32IZbb-NEXT: .LBB1_2:
111 %tmp = call i64 @llvm.sadd.sat.i64(i64 %x, i64 %y);
115 define signext i16 @func16(i16 signext %x, i16 signext %y) nounwind {
116 ; RV32I-LABEL: func16:
118 ; RV32I-NEXT: add a0, a0, a1
119 ; RV32I-NEXT: lui a1, 8
120 ; RV32I-NEXT: addi a1, a1, -1
121 ; RV32I-NEXT: bge a0, a1, .LBB2_3
122 ; RV32I-NEXT: # %bb.1:
123 ; RV32I-NEXT: lui a1, 1048568
124 ; RV32I-NEXT: bge a1, a0, .LBB2_4
125 ; RV32I-NEXT: .LBB2_2:
127 ; RV32I-NEXT: .LBB2_3:
128 ; RV32I-NEXT: mv a0, a1
129 ; RV32I-NEXT: lui a1, 1048568
130 ; RV32I-NEXT: blt a1, a0, .LBB2_2
131 ; RV32I-NEXT: .LBB2_4:
132 ; RV32I-NEXT: lui a0, 1048568
135 ; RV64I-LABEL: func16:
137 ; RV64I-NEXT: add a0, a0, a1
138 ; RV64I-NEXT: lui a1, 8
139 ; RV64I-NEXT: addiw a1, a1, -1
140 ; RV64I-NEXT: bge a0, a1, .LBB2_3
141 ; RV64I-NEXT: # %bb.1:
142 ; RV64I-NEXT: lui a1, 1048568
143 ; RV64I-NEXT: bge a1, a0, .LBB2_4
144 ; RV64I-NEXT: .LBB2_2:
146 ; RV64I-NEXT: .LBB2_3:
147 ; RV64I-NEXT: mv a0, a1
148 ; RV64I-NEXT: lui a1, 1048568
149 ; RV64I-NEXT: blt a1, a0, .LBB2_2
150 ; RV64I-NEXT: .LBB2_4:
151 ; RV64I-NEXT: lui a0, 1048568
154 ; RV32IZbb-LABEL: func16:
156 ; RV32IZbb-NEXT: add 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: add a0, a0, a1
167 ; RV64IZbb-NEXT: lui a1, 8
168 ; RV64IZbb-NEXT: addiw a1, a1, -1
169 ; RV64IZbb-NEXT: min a0, a0, a1
170 ; RV64IZbb-NEXT: lui a1, 1048568
171 ; RV64IZbb-NEXT: max a0, a0, a1
173 %tmp = call i16 @llvm.sadd.sat.i16(i16 %x, i16 %y);
177 define signext i8 @func8(i8 signext %x, i8 signext %y) nounwind {
178 ; RV32I-LABEL: func8:
180 ; RV32I-NEXT: add a0, a0, a1
181 ; RV32I-NEXT: li a1, 127
182 ; RV32I-NEXT: bge a0, a1, .LBB3_3
183 ; RV32I-NEXT: # %bb.1:
184 ; RV32I-NEXT: li a1, -128
185 ; RV32I-NEXT: bge a1, a0, .LBB3_4
186 ; RV32I-NEXT: .LBB3_2:
188 ; RV32I-NEXT: .LBB3_3:
189 ; RV32I-NEXT: li a0, 127
190 ; RV32I-NEXT: li a1, -128
191 ; RV32I-NEXT: blt a1, a0, .LBB3_2
192 ; RV32I-NEXT: .LBB3_4:
193 ; RV32I-NEXT: li a0, -128
196 ; RV64I-LABEL: func8:
198 ; RV64I-NEXT: add a0, a0, a1
199 ; RV64I-NEXT: li a1, 127
200 ; RV64I-NEXT: bge a0, a1, .LBB3_3
201 ; RV64I-NEXT: # %bb.1:
202 ; RV64I-NEXT: li a1, -128
203 ; RV64I-NEXT: bge a1, a0, .LBB3_4
204 ; RV64I-NEXT: .LBB3_2:
206 ; RV64I-NEXT: .LBB3_3:
207 ; RV64I-NEXT: li a0, 127
208 ; RV64I-NEXT: li a1, -128
209 ; RV64I-NEXT: blt a1, a0, .LBB3_2
210 ; RV64I-NEXT: .LBB3_4:
211 ; RV64I-NEXT: li a0, -128
214 ; RV32IZbb-LABEL: func8:
216 ; RV32IZbb-NEXT: add a0, a0, a1
217 ; RV32IZbb-NEXT: li a1, 127
218 ; RV32IZbb-NEXT: min a0, a0, a1
219 ; RV32IZbb-NEXT: li a1, -128
220 ; RV32IZbb-NEXT: max a0, a0, a1
223 ; RV64IZbb-LABEL: func8:
225 ; RV64IZbb-NEXT: add a0, a0, a1
226 ; RV64IZbb-NEXT: li a1, 127
227 ; RV64IZbb-NEXT: min a0, a0, a1
228 ; RV64IZbb-NEXT: li a1, -128
229 ; RV64IZbb-NEXT: max a0, a0, a1
231 %tmp = call i8 @llvm.sadd.sat.i8(i8 %x, i8 %y);
235 define signext i4 @func3(i4 signext %x, i4 signext %y) nounwind {
236 ; RV32I-LABEL: func3:
238 ; RV32I-NEXT: add a0, a0, a1
239 ; RV32I-NEXT: li a1, 7
240 ; RV32I-NEXT: bge a0, a1, .LBB4_3
241 ; RV32I-NEXT: # %bb.1:
242 ; RV32I-NEXT: li a1, -8
243 ; RV32I-NEXT: bge a1, a0, .LBB4_4
244 ; RV32I-NEXT: .LBB4_2:
246 ; RV32I-NEXT: .LBB4_3:
247 ; RV32I-NEXT: li a0, 7
248 ; RV32I-NEXT: li a1, -8
249 ; RV32I-NEXT: blt a1, a0, .LBB4_2
250 ; RV32I-NEXT: .LBB4_4:
251 ; RV32I-NEXT: li a0, -8
254 ; RV64I-LABEL: func3:
256 ; RV64I-NEXT: add a0, a0, a1
257 ; RV64I-NEXT: li a1, 7
258 ; RV64I-NEXT: bge a0, a1, .LBB4_3
259 ; RV64I-NEXT: # %bb.1:
260 ; RV64I-NEXT: li a1, -8
261 ; RV64I-NEXT: bge a1, a0, .LBB4_4
262 ; RV64I-NEXT: .LBB4_2:
264 ; RV64I-NEXT: .LBB4_3:
265 ; RV64I-NEXT: li a0, 7
266 ; RV64I-NEXT: li a1, -8
267 ; RV64I-NEXT: blt a1, a0, .LBB4_2
268 ; RV64I-NEXT: .LBB4_4:
269 ; RV64I-NEXT: li a0, -8
272 ; RV32IZbb-LABEL: func3:
274 ; RV32IZbb-NEXT: add a0, a0, a1
275 ; RV32IZbb-NEXT: li a1, 7
276 ; RV32IZbb-NEXT: min a0, a0, a1
277 ; RV32IZbb-NEXT: li a1, -8
278 ; RV32IZbb-NEXT: max a0, a0, a1
281 ; RV64IZbb-LABEL: func3:
283 ; RV64IZbb-NEXT: add a0, a0, a1
284 ; RV64IZbb-NEXT: li a1, 7
285 ; RV64IZbb-NEXT: min a0, a0, a1
286 ; RV64IZbb-NEXT: li a1, -8
287 ; RV64IZbb-NEXT: max a0, a0, a1
289 %tmp = call i4 @llvm.sadd.sat.i4(i4 %x, i4 %y);