1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=riscv32 -mattr=+m | FileCheck %s --check-prefix=RV32I
3 ; RUN: llc < %s -mtriple=riscv64 -mattr=+m | FileCheck %s --check-prefix=RV64I
4 ; RUN: llc < %s -mtriple=riscv32 -mattr=+m,+experimental-zbb | FileCheck %s --check-prefix=RV32IZbb
5 ; RUN: llc < %s -mtriple=riscv64 -mattr=+m,+experimental-zbb | FileCheck %s --check-prefix=RV64IZbb
7 declare i4 @llvm.uadd.sat.i4(i4, i4)
8 declare i8 @llvm.uadd.sat.i8(i8, i8)
9 declare i16 @llvm.uadd.sat.i16(i16, i16)
10 declare i32 @llvm.uadd.sat.i32(i32, i32)
11 declare i64 @llvm.uadd.sat.i64(i64, i64)
13 define i32 @func32(i32 %x, i32 %y, i32 %z) nounwind {
14 ; RV32I-LABEL: func32:
16 ; RV32I-NEXT: mv a3, a0
17 ; RV32I-NEXT: mul a0, a1, a2
18 ; RV32I-NEXT: add a1, a3, a0
19 ; RV32I-NEXT: addi a0, zero, -1
20 ; RV32I-NEXT: bltu a1, a3, .LBB0_2
21 ; RV32I-NEXT: # %bb.1:
22 ; RV32I-NEXT: mv a0, a1
23 ; RV32I-NEXT: .LBB0_2:
26 ; RV64I-LABEL: func32:
28 ; RV64I-NEXT: mulw a1, a1, a2
29 ; RV64I-NEXT: addw a1, a0, a1
30 ; RV64I-NEXT: sext.w a2, a0
31 ; RV64I-NEXT: addi a0, zero, -1
32 ; RV64I-NEXT: bltu a1, a2, .LBB0_2
33 ; RV64I-NEXT: # %bb.1:
34 ; RV64I-NEXT: mv a0, a1
35 ; RV64I-NEXT: .LBB0_2:
38 ; RV32IZbb-LABEL: func32:
40 ; RV32IZbb-NEXT: mul a1, a1, a2
41 ; RV32IZbb-NEXT: not a2, a1
42 ; RV32IZbb-NEXT: minu a0, a0, a2
43 ; RV32IZbb-NEXT: add a0, a0, a1
46 ; RV64IZbb-LABEL: func32:
48 ; RV64IZbb-NEXT: mulw a1, a1, a2
49 ; RV64IZbb-NEXT: not a2, a1
50 ; RV64IZbb-NEXT: sext.w a0, a0
51 ; RV64IZbb-NEXT: minu a0, a0, a2
52 ; RV64IZbb-NEXT: add a0, a0, a1
55 %tmp = call i32 @llvm.uadd.sat.i32(i32 %x, i32 %a)
59 define i64 @func64(i64 %x, i64 %y, i64 %z) nounwind {
60 ; RV32I-LABEL: func64:
62 ; RV32I-NEXT: add a3, a1, a5
63 ; RV32I-NEXT: add a2, a0, a4
64 ; RV32I-NEXT: sltu a4, a2, a0
65 ; RV32I-NEXT: add a3, a3, a4
66 ; RV32I-NEXT: beq a3, a1, .LBB1_2
67 ; RV32I-NEXT: # %bb.1:
68 ; RV32I-NEXT: sltu a4, a3, a1
69 ; RV32I-NEXT: .LBB1_2:
70 ; RV32I-NEXT: addi a0, zero, -1
71 ; RV32I-NEXT: addi a1, zero, -1
72 ; RV32I-NEXT: bnez a4, .LBB1_4
73 ; RV32I-NEXT: # %bb.3:
74 ; RV32I-NEXT: mv a0, a2
75 ; RV32I-NEXT: mv a1, a3
76 ; RV32I-NEXT: .LBB1_4:
79 ; RV64I-LABEL: func64:
81 ; RV64I-NEXT: mv a1, a0
82 ; RV64I-NEXT: add a2, a0, a2
83 ; RV64I-NEXT: addi a0, zero, -1
84 ; RV64I-NEXT: bltu a2, a1, .LBB1_2
85 ; RV64I-NEXT: # %bb.1:
86 ; RV64I-NEXT: mv a0, a2
87 ; RV64I-NEXT: .LBB1_2:
90 ; RV32IZbb-LABEL: func64:
92 ; RV32IZbb-NEXT: add a3, a1, a5
93 ; RV32IZbb-NEXT: add a2, a0, a4
94 ; RV32IZbb-NEXT: sltu a4, a2, a0
95 ; RV32IZbb-NEXT: add a3, a3, a4
96 ; RV32IZbb-NEXT: beq a3, a1, .LBB1_2
97 ; RV32IZbb-NEXT: # %bb.1:
98 ; RV32IZbb-NEXT: sltu a4, a3, a1
99 ; RV32IZbb-NEXT: .LBB1_2:
100 ; RV32IZbb-NEXT: addi a0, zero, -1
101 ; RV32IZbb-NEXT: addi a1, zero, -1
102 ; RV32IZbb-NEXT: bnez a4, .LBB1_4
103 ; RV32IZbb-NEXT: # %bb.3:
104 ; RV32IZbb-NEXT: mv a0, a2
105 ; RV32IZbb-NEXT: mv a1, a3
106 ; RV32IZbb-NEXT: .LBB1_4:
109 ; RV64IZbb-LABEL: func64:
111 ; RV64IZbb-NEXT: not a1, a2
112 ; RV64IZbb-NEXT: minu a0, a0, a1
113 ; RV64IZbb-NEXT: add a0, a0, a2
116 %tmp = call i64 @llvm.uadd.sat.i64(i64 %x, i64 %z)
120 define i16 @func16(i16 %x, i16 %y, i16 %z) nounwind {
121 ; RV32I-LABEL: func16:
123 ; RV32I-NEXT: lui a3, 16
124 ; RV32I-NEXT: addi a3, a3, -1
125 ; RV32I-NEXT: and a0, a0, a3
126 ; RV32I-NEXT: mul a1, a1, a2
127 ; RV32I-NEXT: and a1, a1, a3
128 ; RV32I-NEXT: add a0, a0, a1
129 ; RV32I-NEXT: bltu a0, a3, .LBB2_2
130 ; RV32I-NEXT: # %bb.1:
131 ; RV32I-NEXT: mv a0, a3
132 ; RV32I-NEXT: .LBB2_2:
135 ; RV64I-LABEL: func16:
137 ; RV64I-NEXT: lui a3, 16
138 ; RV64I-NEXT: addiw a3, a3, -1
139 ; RV64I-NEXT: and a0, a0, a3
140 ; RV64I-NEXT: mul a1, a1, a2
141 ; RV64I-NEXT: and a1, a1, a3
142 ; RV64I-NEXT: add a0, a0, a1
143 ; RV64I-NEXT: bltu a0, a3, .LBB2_2
144 ; RV64I-NEXT: # %bb.1:
145 ; RV64I-NEXT: mv a0, a3
146 ; RV64I-NEXT: .LBB2_2:
149 ; RV32IZbb-LABEL: func16:
151 ; RV32IZbb-NEXT: zext.h a0, a0
152 ; RV32IZbb-NEXT: mul a1, a1, a2
153 ; RV32IZbb-NEXT: zext.h a1, a1
154 ; RV32IZbb-NEXT: add a0, a0, a1
155 ; RV32IZbb-NEXT: lui a1, 16
156 ; RV32IZbb-NEXT: addi a1, a1, -1
157 ; RV32IZbb-NEXT: minu a0, a0, a1
160 ; RV64IZbb-LABEL: func16:
162 ; RV64IZbb-NEXT: zext.h a0, a0
163 ; RV64IZbb-NEXT: mul a1, a1, a2
164 ; RV64IZbb-NEXT: zext.h a1, a1
165 ; RV64IZbb-NEXT: add a0, a0, a1
166 ; RV64IZbb-NEXT: lui a1, 16
167 ; RV64IZbb-NEXT: addiw a1, a1, -1
168 ; RV64IZbb-NEXT: minu a0, a0, a1
171 %tmp = call i16 @llvm.uadd.sat.i16(i16 %x, i16 %a)
175 define i8 @func8(i8 %x, i8 %y, i8 %z) nounwind {
176 ; RV32I-LABEL: func8:
178 ; RV32I-NEXT: andi a0, a0, 255
179 ; RV32I-NEXT: mul a1, a1, a2
180 ; RV32I-NEXT: andi a1, a1, 255
181 ; RV32I-NEXT: add a0, a0, a1
182 ; RV32I-NEXT: addi a1, zero, 255
183 ; RV32I-NEXT: bltu a0, a1, .LBB3_2
184 ; RV32I-NEXT: # %bb.1:
185 ; RV32I-NEXT: addi a0, zero, 255
186 ; RV32I-NEXT: .LBB3_2:
189 ; RV64I-LABEL: func8:
191 ; RV64I-NEXT: andi a0, a0, 255
192 ; RV64I-NEXT: mul a1, a1, a2
193 ; RV64I-NEXT: andi a1, a1, 255
194 ; RV64I-NEXT: add a0, a0, a1
195 ; RV64I-NEXT: addi a1, zero, 255
196 ; RV64I-NEXT: bltu a0, a1, .LBB3_2
197 ; RV64I-NEXT: # %bb.1:
198 ; RV64I-NEXT: addi a0, zero, 255
199 ; RV64I-NEXT: .LBB3_2:
202 ; RV32IZbb-LABEL: func8:
204 ; RV32IZbb-NEXT: andi a0, a0, 255
205 ; RV32IZbb-NEXT: mul a1, a1, a2
206 ; RV32IZbb-NEXT: andi a1, a1, 255
207 ; RV32IZbb-NEXT: add a0, a0, a1
208 ; RV32IZbb-NEXT: addi a1, zero, 255
209 ; RV32IZbb-NEXT: minu a0, a0, a1
212 ; RV64IZbb-LABEL: func8:
214 ; RV64IZbb-NEXT: andi a0, a0, 255
215 ; RV64IZbb-NEXT: mul a1, a1, a2
216 ; RV64IZbb-NEXT: andi a1, a1, 255
217 ; RV64IZbb-NEXT: add a0, a0, a1
218 ; RV64IZbb-NEXT: addi a1, zero, 255
219 ; RV64IZbb-NEXT: minu a0, a0, a1
222 %tmp = call i8 @llvm.uadd.sat.i8(i8 %x, i8 %a)
226 define i4 @func4(i4 %x, i4 %y, i4 %z) nounwind {
227 ; RV32I-LABEL: func4:
229 ; RV32I-NEXT: andi a0, a0, 15
230 ; RV32I-NEXT: mul a1, a1, a2
231 ; RV32I-NEXT: andi a1, a1, 15
232 ; RV32I-NEXT: add a0, a0, a1
233 ; RV32I-NEXT: addi a1, zero, 15
234 ; RV32I-NEXT: bltu a0, a1, .LBB4_2
235 ; RV32I-NEXT: # %bb.1:
236 ; RV32I-NEXT: addi a0, zero, 15
237 ; RV32I-NEXT: .LBB4_2:
240 ; RV64I-LABEL: func4:
242 ; RV64I-NEXT: andi a0, a0, 15
243 ; RV64I-NEXT: mul a1, a1, a2
244 ; RV64I-NEXT: andi a1, a1, 15
245 ; RV64I-NEXT: add a0, a0, a1
246 ; RV64I-NEXT: addi a1, zero, 15
247 ; RV64I-NEXT: bltu a0, a1, .LBB4_2
248 ; RV64I-NEXT: # %bb.1:
249 ; RV64I-NEXT: addi a0, zero, 15
250 ; RV64I-NEXT: .LBB4_2:
253 ; RV32IZbb-LABEL: func4:
255 ; RV32IZbb-NEXT: andi a0, a0, 15
256 ; RV32IZbb-NEXT: mul a1, a1, a2
257 ; RV32IZbb-NEXT: andi a1, a1, 15
258 ; RV32IZbb-NEXT: add a0, a0, a1
259 ; RV32IZbb-NEXT: addi a1, zero, 15
260 ; RV32IZbb-NEXT: minu a0, a0, a1
263 ; RV64IZbb-LABEL: func4:
265 ; RV64IZbb-NEXT: andi a0, a0, 15
266 ; RV64IZbb-NEXT: mul a1, a1, a2
267 ; RV64IZbb-NEXT: andi a1, a1, 15
268 ; RV64IZbb-NEXT: add a0, a0, a1
269 ; RV64IZbb-NEXT: addi a1, zero, 15
270 ; RV64IZbb-NEXT: minu a0, a0, a1
273 %tmp = call i4 @llvm.uadd.sat.i4(i4 %x, i4 %a)