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 signext i32 @func(i32 signext %x, i32 signext %y) nounwind {
16 ; RV32-NEXT: mv a2, a0
17 ; RV32-NEXT: sgtz a3, a1
18 ; RV32-NEXT: sub a0, a0, a1
19 ; RV32-NEXT: slt a1, a0, a2
20 ; RV32-NEXT: beq a3, a1, .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: sub 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: 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
53 %tmp = call i32 @llvm.ssub.sat.i32(i32 %x, i32 %y);
57 define i64 @func2(i64 %x, i64 %y) nounwind {
60 ; RV32-NEXT: mv a4, a1
61 ; RV32-NEXT: sltu a1, a0, a2
62 ; RV32-NEXT: sub a5, a4, a3
63 ; RV32-NEXT: sub a1, a5, a1
64 ; RV32-NEXT: xor a5, a4, a1
65 ; RV32-NEXT: xor a3, a4, a3
66 ; RV32-NEXT: and a3, a3, a5
67 ; RV32-NEXT: bltz a3, .LBB1_2
69 ; RV32-NEXT: sub a0, a0, a2
72 ; RV32-NEXT: srai a0, a1, 31
73 ; RV32-NEXT: lui a1, 524288
74 ; RV32-NEXT: xor a1, a0, a1
79 ; RV64-NEXT: mv a2, a0
80 ; RV64-NEXT: sgtz a3, a1
81 ; RV64-NEXT: sub a0, a0, a1
82 ; RV64-NEXT: slt a1, a0, a2
83 ; RV64-NEXT: beq a3, a1, .LBB1_2
85 ; RV64-NEXT: srai a0, a0, 63
86 ; RV64-NEXT: li a1, -1
87 ; RV64-NEXT: slli a1, a1, 63
88 ; RV64-NEXT: xor a0, a0, a1
91 %tmp = call i64 @llvm.ssub.sat.i64(i64 %x, i64 %y);
95 define signext i16 @func16(i16 signext %x, i16 signext %y) nounwind {
96 ; RV32I-LABEL: func16:
98 ; RV32I-NEXT: sub a0, a0, a1
99 ; RV32I-NEXT: lui a1, 8
100 ; RV32I-NEXT: addi a1, a1, -1
101 ; RV32I-NEXT: bge a0, a1, .LBB2_3
102 ; RV32I-NEXT: # %bb.1:
103 ; RV32I-NEXT: lui a1, 1048568
104 ; RV32I-NEXT: bge a1, a0, .LBB2_4
105 ; RV32I-NEXT: .LBB2_2:
107 ; RV32I-NEXT: .LBB2_3:
108 ; RV32I-NEXT: mv a0, a1
109 ; RV32I-NEXT: lui a1, 1048568
110 ; RV32I-NEXT: blt a1, a0, .LBB2_2
111 ; RV32I-NEXT: .LBB2_4:
112 ; RV32I-NEXT: lui a0, 1048568
115 ; RV64I-LABEL: func16:
117 ; RV64I-NEXT: sub a0, a0, a1
118 ; RV64I-NEXT: lui a1, 8
119 ; RV64I-NEXT: addiw a1, a1, -1
120 ; RV64I-NEXT: bge a0, a1, .LBB2_3
121 ; RV64I-NEXT: # %bb.1:
122 ; RV64I-NEXT: lui a1, 1048568
123 ; RV64I-NEXT: bge a1, a0, .LBB2_4
124 ; RV64I-NEXT: .LBB2_2:
126 ; RV64I-NEXT: .LBB2_3:
127 ; RV64I-NEXT: mv a0, a1
128 ; RV64I-NEXT: lui a1, 1048568
129 ; RV64I-NEXT: blt a1, a0, .LBB2_2
130 ; RV64I-NEXT: .LBB2_4:
131 ; RV64I-NEXT: lui a0, 1048568
134 ; RV32IZbb-LABEL: func16:
136 ; RV32IZbb-NEXT: sub a0, a0, a1
137 ; RV32IZbb-NEXT: lui a1, 8
138 ; RV32IZbb-NEXT: addi a1, a1, -1
139 ; RV32IZbb-NEXT: min a0, a0, a1
140 ; RV32IZbb-NEXT: lui a1, 1048568
141 ; RV32IZbb-NEXT: max a0, a0, a1
144 ; RV64IZbb-LABEL: func16:
146 ; RV64IZbb-NEXT: sub a0, a0, a1
147 ; RV64IZbb-NEXT: lui a1, 8
148 ; RV64IZbb-NEXT: addiw a1, a1, -1
149 ; RV64IZbb-NEXT: min a0, a0, a1
150 ; RV64IZbb-NEXT: lui a1, 1048568
151 ; RV64IZbb-NEXT: max a0, a0, a1
153 %tmp = call i16 @llvm.ssub.sat.i16(i16 %x, i16 %y);
157 define signext i8 @func8(i8 signext %x, i8 signext %y) nounwind {
158 ; RV32I-LABEL: func8:
160 ; RV32I-NEXT: sub a0, a0, a1
161 ; RV32I-NEXT: li a1, 127
162 ; RV32I-NEXT: bge a0, a1, .LBB3_3
163 ; RV32I-NEXT: # %bb.1:
164 ; RV32I-NEXT: li a1, -128
165 ; RV32I-NEXT: bge a1, a0, .LBB3_4
166 ; RV32I-NEXT: .LBB3_2:
168 ; RV32I-NEXT: .LBB3_3:
169 ; RV32I-NEXT: li a0, 127
170 ; RV32I-NEXT: li a1, -128
171 ; RV32I-NEXT: blt a1, a0, .LBB3_2
172 ; RV32I-NEXT: .LBB3_4:
173 ; RV32I-NEXT: li a0, -128
176 ; RV64I-LABEL: func8:
178 ; RV64I-NEXT: sub a0, a0, a1
179 ; RV64I-NEXT: li a1, 127
180 ; RV64I-NEXT: bge a0, a1, .LBB3_3
181 ; RV64I-NEXT: # %bb.1:
182 ; RV64I-NEXT: li a1, -128
183 ; RV64I-NEXT: bge a1, a0, .LBB3_4
184 ; RV64I-NEXT: .LBB3_2:
186 ; RV64I-NEXT: .LBB3_3:
187 ; RV64I-NEXT: li a0, 127
188 ; RV64I-NEXT: li a1, -128
189 ; RV64I-NEXT: blt a1, a0, .LBB3_2
190 ; RV64I-NEXT: .LBB3_4:
191 ; RV64I-NEXT: li a0, -128
194 ; RV32IZbb-LABEL: func8:
196 ; RV32IZbb-NEXT: sub a0, a0, a1
197 ; RV32IZbb-NEXT: li a1, 127
198 ; RV32IZbb-NEXT: min a0, a0, a1
199 ; RV32IZbb-NEXT: li a1, -128
200 ; RV32IZbb-NEXT: max a0, a0, a1
203 ; RV64IZbb-LABEL: func8:
205 ; RV64IZbb-NEXT: sub a0, a0, a1
206 ; RV64IZbb-NEXT: li a1, 127
207 ; RV64IZbb-NEXT: min a0, a0, a1
208 ; RV64IZbb-NEXT: li a1, -128
209 ; RV64IZbb-NEXT: max a0, a0, a1
211 %tmp = call i8 @llvm.ssub.sat.i8(i8 %x, i8 %y);
215 define signext i4 @func3(i4 signext %x, i4 signext %y) nounwind {
216 ; RV32I-LABEL: func3:
218 ; RV32I-NEXT: sub a0, a0, a1
219 ; RV32I-NEXT: li a1, 7
220 ; RV32I-NEXT: bge a0, a1, .LBB4_3
221 ; RV32I-NEXT: # %bb.1:
222 ; RV32I-NEXT: li a1, -8
223 ; RV32I-NEXT: bge a1, a0, .LBB4_4
224 ; RV32I-NEXT: .LBB4_2:
226 ; RV32I-NEXT: .LBB4_3:
227 ; RV32I-NEXT: li a0, 7
228 ; RV32I-NEXT: li a1, -8
229 ; RV32I-NEXT: blt a1, a0, .LBB4_2
230 ; RV32I-NEXT: .LBB4_4:
231 ; RV32I-NEXT: li a0, -8
234 ; RV64I-LABEL: func3:
236 ; RV64I-NEXT: sub a0, a0, a1
237 ; RV64I-NEXT: li a1, 7
238 ; RV64I-NEXT: bge a0, a1, .LBB4_3
239 ; RV64I-NEXT: # %bb.1:
240 ; RV64I-NEXT: li a1, -8
241 ; RV64I-NEXT: bge a1, a0, .LBB4_4
242 ; RV64I-NEXT: .LBB4_2:
244 ; RV64I-NEXT: .LBB4_3:
245 ; RV64I-NEXT: li a0, 7
246 ; RV64I-NEXT: li a1, -8
247 ; RV64I-NEXT: blt a1, a0, .LBB4_2
248 ; RV64I-NEXT: .LBB4_4:
249 ; RV64I-NEXT: li a0, -8
252 ; RV32IZbb-LABEL: func3:
254 ; RV32IZbb-NEXT: sub a0, a0, a1
255 ; RV32IZbb-NEXT: li a1, 7
256 ; RV32IZbb-NEXT: min a0, a0, a1
257 ; RV32IZbb-NEXT: li a1, -8
258 ; RV32IZbb-NEXT: max a0, a0, a1
261 ; RV64IZbb-LABEL: func3:
263 ; RV64IZbb-NEXT: sub a0, a0, a1
264 ; RV64IZbb-NEXT: li a1, 7
265 ; RV64IZbb-NEXT: min a0, a0, a1
266 ; RV64IZbb-NEXT: li a1, -8
267 ; RV64IZbb-NEXT: max a0, a0, a1
269 %tmp = call i4 @llvm.ssub.sat.i4(i4 %x, i4 %y);