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,+zbb | FileCheck %s --check-prefix=RV32IZbb
5 ; RUN: llc < %s -mtriple=riscv64 -mattr=+m,+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 signext i32 @func(i32 signext %x, i32 signext %y) nounwind {
16 ; RV32I-NEXT: mv a2, a0
17 ; RV32I-NEXT: add a1, a0, a1
18 ; RV32I-NEXT: li a0, -1
19 ; RV32I-NEXT: bltu a1, a2, .LBB0_2
20 ; RV32I-NEXT: # %bb.1:
21 ; RV32I-NEXT: mv a0, a1
22 ; RV32I-NEXT: .LBB0_2:
27 ; RV64I-NEXT: mv a2, a0
28 ; RV64I-NEXT: addw a1, a0, a1
29 ; RV64I-NEXT: li a0, -1
30 ; RV64I-NEXT: bltu a1, a2, .LBB0_2
31 ; RV64I-NEXT: # %bb.1:
32 ; RV64I-NEXT: mv a0, a1
33 ; RV64I-NEXT: .LBB0_2:
36 ; RV32IZbb-LABEL: func:
38 ; RV32IZbb-NEXT: not a2, a1
39 ; RV32IZbb-NEXT: minu a0, a0, a2
40 ; RV32IZbb-NEXT: add a0, a0, a1
43 ; RV64IZbb-LABEL: func:
45 ; RV64IZbb-NEXT: not a2, a1
46 ; RV64IZbb-NEXT: minu a0, a0, a2
47 ; RV64IZbb-NEXT: addw a0, a0, a1
49 %tmp = call i32 @llvm.uadd.sat.i32(i32 %x, i32 %y);
53 define i64 @func2(i64 %x, i64 %y) nounwind {
56 ; RV32I-NEXT: add a3, a1, a3
57 ; RV32I-NEXT: add a2, a0, a2
58 ; RV32I-NEXT: sltu a4, a2, a0
59 ; RV32I-NEXT: add a3, a3, a4
60 ; RV32I-NEXT: beq a3, a1, .LBB1_2
61 ; RV32I-NEXT: # %bb.1:
62 ; RV32I-NEXT: sltu a4, a3, a1
63 ; RV32I-NEXT: .LBB1_2:
64 ; RV32I-NEXT: li a0, -1
65 ; RV32I-NEXT: li a1, -1
66 ; RV32I-NEXT: bnez a4, .LBB1_4
67 ; RV32I-NEXT: # %bb.3:
68 ; RV32I-NEXT: mv a0, a2
69 ; RV32I-NEXT: mv a1, a3
70 ; RV32I-NEXT: .LBB1_4:
75 ; RV64I-NEXT: mv a2, a0
76 ; RV64I-NEXT: add a1, a0, a1
77 ; RV64I-NEXT: li a0, -1
78 ; RV64I-NEXT: bltu a1, a2, .LBB1_2
79 ; RV64I-NEXT: # %bb.1:
80 ; RV64I-NEXT: mv a0, a1
81 ; RV64I-NEXT: .LBB1_2:
84 ; RV32IZbb-LABEL: func2:
86 ; RV32IZbb-NEXT: add a3, a1, a3
87 ; RV32IZbb-NEXT: add a2, a0, a2
88 ; RV32IZbb-NEXT: sltu a4, a2, a0
89 ; RV32IZbb-NEXT: add a3, a3, a4
90 ; RV32IZbb-NEXT: beq a3, a1, .LBB1_2
91 ; RV32IZbb-NEXT: # %bb.1:
92 ; RV32IZbb-NEXT: sltu a4, a3, a1
93 ; RV32IZbb-NEXT: .LBB1_2:
94 ; RV32IZbb-NEXT: li a0, -1
95 ; RV32IZbb-NEXT: li a1, -1
96 ; RV32IZbb-NEXT: bnez a4, .LBB1_4
97 ; RV32IZbb-NEXT: # %bb.3:
98 ; RV32IZbb-NEXT: mv a0, a2
99 ; RV32IZbb-NEXT: mv a1, a3
100 ; RV32IZbb-NEXT: .LBB1_4:
103 ; RV64IZbb-LABEL: func2:
105 ; RV64IZbb-NEXT: not a2, a1
106 ; RV64IZbb-NEXT: minu a0, a0, a2
107 ; RV64IZbb-NEXT: add a0, a0, a1
109 %tmp = call i64 @llvm.uadd.sat.i64(i64 %x, i64 %y);
113 define zeroext i16 @func16(i16 zeroext %x, i16 zeroext %y) nounwind {
114 ; RV32I-LABEL: func16:
116 ; RV32I-NEXT: add a0, a0, a1
117 ; RV32I-NEXT: lui a1, 16
118 ; RV32I-NEXT: addi a1, a1, -1
119 ; RV32I-NEXT: bltu a0, a1, .LBB2_2
120 ; RV32I-NEXT: # %bb.1:
121 ; RV32I-NEXT: mv a0, a1
122 ; RV32I-NEXT: .LBB2_2:
125 ; RV64I-LABEL: func16:
127 ; RV64I-NEXT: add a0, a0, a1
128 ; RV64I-NEXT: lui a1, 16
129 ; RV64I-NEXT: addiw a1, a1, -1
130 ; RV64I-NEXT: bltu a0, a1, .LBB2_2
131 ; RV64I-NEXT: # %bb.1:
132 ; RV64I-NEXT: mv a0, a1
133 ; RV64I-NEXT: .LBB2_2:
136 ; RV32IZbb-LABEL: func16:
138 ; RV32IZbb-NEXT: add a0, a0, a1
139 ; RV32IZbb-NEXT: lui a1, 16
140 ; RV32IZbb-NEXT: addi a1, a1, -1
141 ; RV32IZbb-NEXT: minu a0, a0, a1
144 ; RV64IZbb-LABEL: func16:
146 ; RV64IZbb-NEXT: add a0, a0, a1
147 ; RV64IZbb-NEXT: lui a1, 16
148 ; RV64IZbb-NEXT: addiw a1, a1, -1
149 ; RV64IZbb-NEXT: minu a0, a0, a1
151 %tmp = call i16 @llvm.uadd.sat.i16(i16 %x, i16 %y);
155 define zeroext i8 @func8(i8 zeroext %x, i8 zeroext %y) nounwind {
156 ; RV32I-LABEL: func8:
158 ; RV32I-NEXT: add a0, a0, a1
159 ; RV32I-NEXT: li a1, 255
160 ; RV32I-NEXT: bltu a0, a1, .LBB3_2
161 ; RV32I-NEXT: # %bb.1:
162 ; RV32I-NEXT: li a0, 255
163 ; RV32I-NEXT: .LBB3_2:
166 ; RV64I-LABEL: func8:
168 ; RV64I-NEXT: add a0, a0, a1
169 ; RV64I-NEXT: li a1, 255
170 ; RV64I-NEXT: bltu a0, a1, .LBB3_2
171 ; RV64I-NEXT: # %bb.1:
172 ; RV64I-NEXT: li a0, 255
173 ; RV64I-NEXT: .LBB3_2:
176 ; RV32IZbb-LABEL: func8:
178 ; RV32IZbb-NEXT: add a0, a0, a1
179 ; RV32IZbb-NEXT: li a1, 255
180 ; RV32IZbb-NEXT: minu a0, a0, a1
183 ; RV64IZbb-LABEL: func8:
185 ; RV64IZbb-NEXT: add a0, a0, a1
186 ; RV64IZbb-NEXT: li a1, 255
187 ; RV64IZbb-NEXT: minu a0, a0, a1
189 %tmp = call i8 @llvm.uadd.sat.i8(i8 %x, i8 %y);
193 define zeroext i4 @func3(i4 zeroext %x, i4 zeroext %y) nounwind {
194 ; RV32I-LABEL: func3:
196 ; RV32I-NEXT: add a0, a0, a1
197 ; RV32I-NEXT: li a1, 15
198 ; RV32I-NEXT: bltu a0, a1, .LBB4_2
199 ; RV32I-NEXT: # %bb.1:
200 ; RV32I-NEXT: li a0, 15
201 ; RV32I-NEXT: .LBB4_2:
204 ; RV64I-LABEL: func3:
206 ; RV64I-NEXT: add a0, a0, a1
207 ; RV64I-NEXT: li a1, 15
208 ; RV64I-NEXT: bltu a0, a1, .LBB4_2
209 ; RV64I-NEXT: # %bb.1:
210 ; RV64I-NEXT: li a0, 15
211 ; RV64I-NEXT: .LBB4_2:
214 ; RV32IZbb-LABEL: func3:
216 ; RV32IZbb-NEXT: add a0, a0, a1
217 ; RV32IZbb-NEXT: li a1, 15
218 ; RV32IZbb-NEXT: minu a0, a0, a1
221 ; RV64IZbb-LABEL: func3:
223 ; RV64IZbb-NEXT: add a0, a0, a1
224 ; RV64IZbb-NEXT: li a1, 15
225 ; RV64IZbb-NEXT: minu a0, a0, a1
227 %tmp = call i4 @llvm.uadd.sat.i4(i4 %x, i4 %y);