1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -O2 -mtriple=riscv64 | FileCheck %s
4 define i32 @native_i64(i64 %a) {
5 ; CHECK-LABEL: native_i64:
6 ; CHECK: # %bb.0: # %entry
7 ; CHECK-NEXT: li a1, -1
8 ; CHECK-NEXT: beq a0, a1, .LBB0_3
9 ; CHECK-NEXT: # %bb.1: # %entry
10 ; CHECK-NEXT: li a1, 1
11 ; CHECK-NEXT: bne a0, a1, .LBB0_4
12 ; CHECK-NEXT: # %bb.2: # %sw.bb0
13 ; CHECK-NEXT: li a0, 0
15 ; CHECK-NEXT: .LBB0_3: # %sw.bb1
16 ; CHECK-NEXT: li a0, 1
18 ; CHECK-NEXT: .LBB0_4: # %sw.default
19 ; CHECK-NEXT: li a0, -1
22 switch i64 %a, label %sw.default [
37 %retval = phi i32 [ -1, %sw.default ], [ 0, %sw.bb0 ], [ 1, %sw.bb1 ]
41 define i32 @native_i32(i32 %a) {
42 ; CHECK-LABEL: native_i32:
43 ; CHECK: # %bb.0: # %entry
44 ; CHECK-NEXT: sext.w a0, a0
45 ; CHECK-NEXT: li a1, -1
46 ; CHECK-NEXT: beq a0, a1, .LBB1_3
47 ; CHECK-NEXT: # %bb.1: # %entry
48 ; CHECK-NEXT: li a1, 1
49 ; CHECK-NEXT: bne a0, a1, .LBB1_4
50 ; CHECK-NEXT: # %bb.2: # %sw.bb0
51 ; CHECK-NEXT: li a0, 0
53 ; CHECK-NEXT: .LBB1_3: # %sw.bb1
54 ; CHECK-NEXT: li a0, 1
56 ; CHECK-NEXT: .LBB1_4: # %sw.default
57 ; CHECK-NEXT: li a0, -1
60 switch i32 %a, label %sw.default [
75 %retval = phi i32 [ -1, %sw.default ], [ 0, %sw.bb0 ], [ 1, %sw.bb1 ]
79 define i32 @trunc_i32(i64 %a) {
80 ; CHECK-LABEL: trunc_i32:
81 ; CHECK: # %bb.0: # %entry
82 ; CHECK-NEXT: sext.w a0, a0
83 ; CHECK-NEXT: li a1, -1
84 ; CHECK-NEXT: beq a0, a1, .LBB2_3
85 ; CHECK-NEXT: # %bb.1: # %entry
86 ; CHECK-NEXT: li a1, 1
87 ; CHECK-NEXT: bne a0, a1, .LBB2_4
88 ; CHECK-NEXT: # %bb.2: # %sw.bb0
89 ; CHECK-NEXT: li a0, 0
91 ; CHECK-NEXT: .LBB2_3: # %sw.bb1
92 ; CHECK-NEXT: li a0, 1
94 ; CHECK-NEXT: .LBB2_4: # %sw.default
95 ; CHECK-NEXT: li a0, -1
98 %trunc = trunc i64 %a to i32
99 switch i32 %trunc, label %sw.default [
101 i32 -1, label %sw.bb1
114 %retval = phi i32 [ -1, %sw.default ], [ 0, %sw.bb0 ], [ 1, %sw.bb1 ]
118 define i32 @trunc_i17(i64 %a) {
119 ; CHECK-LABEL: trunc_i17:
120 ; CHECK: # %bb.0: # %entry
121 ; CHECK-NEXT: lui a1, 32
122 ; CHECK-NEXT: addiw a1, a1, -1
123 ; CHECK-NEXT: and a0, a0, a1
124 ; CHECK-NEXT: beq a0, a1, .LBB3_3
125 ; CHECK-NEXT: # %bb.1: # %entry
126 ; CHECK-NEXT: li a1, 1
127 ; CHECK-NEXT: bne a0, a1, .LBB3_4
128 ; CHECK-NEXT: # %bb.2: # %sw.bb0
129 ; CHECK-NEXT: li a0, 0
131 ; CHECK-NEXT: .LBB3_3: # %sw.bb1
132 ; CHECK-NEXT: li a0, 1
134 ; CHECK-NEXT: .LBB3_4: # %sw.default
135 ; CHECK-NEXT: li a0, -1
138 %trunc = trunc i64 %a to i17
139 switch i17 %trunc, label %sw.default [
141 i17 -1, label %sw.bb1
154 %retval = phi i32 [ -1, %sw.default ], [ 0, %sw.bb0 ], [ 1, %sw.bb1 ]
158 define i32 @trunc_i16(i64 %a) {
159 ; CHECK-LABEL: trunc_i16:
160 ; CHECK: # %bb.0: # %entry
161 ; CHECK-NEXT: lui a1, 16
162 ; CHECK-NEXT: addiw a1, a1, -1
163 ; CHECK-NEXT: and a0, a0, a1
164 ; CHECK-NEXT: beq a0, a1, .LBB4_3
165 ; CHECK-NEXT: # %bb.1: # %entry
166 ; CHECK-NEXT: li a1, 1
167 ; CHECK-NEXT: bne a0, a1, .LBB4_4
168 ; CHECK-NEXT: # %bb.2: # %sw.bb0
169 ; CHECK-NEXT: li a0, 0
171 ; CHECK-NEXT: .LBB4_3: # %sw.bb1
172 ; CHECK-NEXT: li a0, 1
174 ; CHECK-NEXT: .LBB4_4: # %sw.default
175 ; CHECK-NEXT: li a0, -1
178 %trunc = trunc i64 %a to i16
179 switch i16 %trunc, label %sw.default [
181 i16 -1, label %sw.bb1
194 %retval = phi i32 [ -1, %sw.default ], [ 0, %sw.bb0 ], [ 1, %sw.bb1 ]
199 define i32 @trunc_i12(i64 %a) {
200 ; CHECK-LABEL: trunc_i12:
201 ; CHECK: # %bb.0: # %entry
202 ; CHECK-NEXT: lui a1, 1
203 ; CHECK-NEXT: addiw a1, a1, -1
204 ; CHECK-NEXT: and a0, a0, a1
205 ; CHECK-NEXT: beq a0, a1, .LBB5_3
206 ; CHECK-NEXT: # %bb.1: # %entry
207 ; CHECK-NEXT: li a1, 1
208 ; CHECK-NEXT: bne a0, a1, .LBB5_4
209 ; CHECK-NEXT: # %bb.2: # %sw.bb0
210 ; CHECK-NEXT: li a0, 0
212 ; CHECK-NEXT: .LBB5_3: # %sw.bb1
213 ; CHECK-NEXT: li a0, 1
215 ; CHECK-NEXT: .LBB5_4: # %sw.default
216 ; CHECK-NEXT: li a0, -1
219 %trunc = trunc i64 %a to i12
220 switch i12 %trunc, label %sw.default [
222 i12 -1, label %sw.bb1
235 %retval = phi i32 [ -1, %sw.default ], [ 0, %sw.bb0 ], [ 1, %sw.bb1 ]
239 define i32 @trunc_i11(i64 %a) {
240 ; CHECK-LABEL: trunc_i11:
241 ; CHECK: # %bb.0: # %entry
242 ; CHECK-NEXT: andi a0, a0, 2047
243 ; CHECK-NEXT: li a1, 2047
244 ; CHECK-NEXT: beq a0, a1, .LBB6_3
245 ; CHECK-NEXT: # %bb.1: # %entry
246 ; CHECK-NEXT: li a1, 1
247 ; CHECK-NEXT: bne a0, a1, .LBB6_4
248 ; CHECK-NEXT: # %bb.2: # %sw.bb0
249 ; CHECK-NEXT: li a0, 0
251 ; CHECK-NEXT: .LBB6_3: # %sw.bb1
252 ; CHECK-NEXT: li a0, 1
254 ; CHECK-NEXT: .LBB6_4: # %sw.default
255 ; CHECK-NEXT: li a0, -1
258 %trunc = trunc i64 %a to i11
259 switch i11 %trunc, label %sw.default [
261 i11 -1, label %sw.bb1
274 %retval = phi i32 [ -1, %sw.default ], [ 0, %sw.bb0 ], [ 1, %sw.bb1 ]
279 define i32 @trunc_i10(i64 %a) {
280 ; CHECK-LABEL: trunc_i10:
281 ; CHECK: # %bb.0: # %entry
282 ; CHECK-NEXT: andi a0, a0, 1023
283 ; CHECK-NEXT: li a1, 1023
284 ; CHECK-NEXT: beq a0, a1, .LBB7_3
285 ; CHECK-NEXT: # %bb.1: # %entry
286 ; CHECK-NEXT: li a1, 1
287 ; CHECK-NEXT: bne a0, a1, .LBB7_4
288 ; CHECK-NEXT: # %bb.2: # %sw.bb0
289 ; CHECK-NEXT: li a0, 0
291 ; CHECK-NEXT: .LBB7_3: # %sw.bb1
292 ; CHECK-NEXT: li a0, 1
294 ; CHECK-NEXT: .LBB7_4: # %sw.default
295 ; CHECK-NEXT: li a0, -1
298 %trunc = trunc i64 %a to i10
299 switch i10 %trunc, label %sw.default [
301 i10 -1, label %sw.bb1
314 %retval = phi i32 [ -1, %sw.default ], [ 0, %sw.bb0 ], [ 1, %sw.bb1 ]