1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 %s -o - | FileCheck %s --check-prefix=RV32
3 ; RUN: llc -mtriple=riscv64 %s -o - | FileCheck %s --check-prefix=RV64
5 define i32 @xori64i32(i64 %a) {
6 ; RV32-LABEL: xori64i32:
8 ; RV32-NEXT: srai a1, a1, 31
9 ; RV32-NEXT: lui a0, 524288
10 ; RV32-NEXT: addi a0, a0, -1
11 ; RV32-NEXT: xor a0, a1, a0
14 ; RV64-LABEL: xori64i32:
16 ; RV64-NEXT: srai a0, a0, 63
17 ; RV64-NEXT: lui a1, 524288
18 ; RV64-NEXT: addiw a1, a1, -1
19 ; RV64-NEXT: xor a0, a0, a1
21 %shr4 = ashr i64 %a, 63
22 %conv5 = trunc i64 %shr4 to i32
23 %xor = xor i32 %conv5, 2147483647
27 define i64 @selecti64i64(i64 %a) {
28 ; RV32-LABEL: selecti64i64:
30 ; RV32-NEXT: srai a1, a1, 31
31 ; RV32-NEXT: lui a0, 524288
32 ; RV32-NEXT: addi a0, a0, -1
33 ; RV32-NEXT: xor a0, a1, a0
36 ; RV64-LABEL: selecti64i64:
38 ; RV64-NEXT: srai a0, a0, 63
39 ; RV64-NEXT: lui a1, 524288
40 ; RV64-NEXT: addiw a1, a1, -1
41 ; RV64-NEXT: xor a0, a0, a1
43 %c = icmp sgt i64 %a, -1
44 %s = select i1 %c, i64 2147483647, i64 -2147483648
48 define i32 @selecti64i32(i64 %a) {
49 ; RV32-LABEL: selecti64i32:
51 ; RV32-NEXT: slti a0, a1, 0
52 ; RV32-NEXT: xori a0, a0, 1
53 ; RV32-NEXT: lui a1, 524288
54 ; RV32-NEXT: sub a0, a1, a0
57 ; RV64-LABEL: selecti64i32:
59 ; RV64-NEXT: srai a0, a0, 63
60 ; RV64-NEXT: lui a1, 524288
61 ; RV64-NEXT: addiw a1, a1, -1
62 ; RV64-NEXT: xor a0, a0, a1
64 %c = icmp sgt i64 %a, -1
65 %s = select i1 %c, i32 2147483647, i32 -2147483648
69 define i64 @selecti32i64(i32 %a) {
70 ; RV32-LABEL: selecti32i64:
72 ; RV32-NEXT: srai a1, a0, 31
73 ; RV32-NEXT: lui a0, 524288
74 ; RV32-NEXT: addi a0, a0, -1
75 ; RV32-NEXT: xor a0, a1, a0
78 ; RV64-LABEL: selecti32i64:
80 ; RV64-NEXT: sraiw a0, a0, 31
81 ; RV64-NEXT: lui a1, 524288
82 ; RV64-NEXT: addiw a1, a1, -1
83 ; RV64-NEXT: xor a0, a0, a1
85 %c = icmp sgt i32 %a, -1
86 %s = select i1 %c, i64 2147483647, i64 -2147483648
92 define i8 @xori32i8(i32 %a) {
93 ; RV32-LABEL: xori32i8:
95 ; RV32-NEXT: srai a0, a0, 31
96 ; RV32-NEXT: xori a0, a0, 84
99 ; RV64-LABEL: xori32i8:
101 ; RV64-NEXT: sraiw a0, a0, 31
102 ; RV64-NEXT: xori a0, a0, 84
104 %shr4 = ashr i32 %a, 31
105 %conv5 = trunc i32 %shr4 to i8
106 %xor = xor i8 %conv5, 84
110 define i32 @selecti32i32(i32 %a) {
111 ; RV32-LABEL: selecti32i32:
113 ; RV32-NEXT: srai a0, a0, 31
114 ; RV32-NEXT: xori a0, a0, 84
117 ; RV64-LABEL: selecti32i32:
119 ; RV64-NEXT: sraiw a0, a0, 31
120 ; RV64-NEXT: xori a0, a0, 84
122 %c = icmp sgt i32 %a, -1
123 %s = select i1 %c, i32 84, i32 -85
127 define i8 @selecti32i8(i32 %a) {
128 ; RV32-LABEL: selecti32i8:
130 ; RV32-NEXT: srai a0, a0, 31
131 ; RV32-NEXT: xori a0, a0, 84
134 ; RV64-LABEL: selecti32i8:
136 ; RV64-NEXT: sraiw a0, a0, 31
137 ; RV64-NEXT: xori a0, a0, 84
139 %c = icmp sgt i32 %a, -1
140 %s = select i1 %c, i8 84, i8 -85
144 define i32 @selecti8i32(i8 %a) {
145 ; RV32-LABEL: selecti8i32:
147 ; RV32-NEXT: slli a0, a0, 24
148 ; RV32-NEXT: srai a0, a0, 31
149 ; RV32-NEXT: xori a0, a0, 84
152 ; RV64-LABEL: selecti8i32:
154 ; RV64-NEXT: slli a0, a0, 56
155 ; RV64-NEXT: srai a0, a0, 63
156 ; RV64-NEXT: xori a0, a0, 84
158 %c = icmp sgt i8 %a, -1
159 %s = select i1 %c, i32 84, i32 -85
163 define i32 @icmpasreq(i32 %input, i32 %a, i32 %b) {
164 ; RV32-LABEL: icmpasreq:
166 ; RV32-NEXT: bltz a0, .LBB8_2
167 ; RV32-NEXT: # %bb.1:
168 ; RV32-NEXT: mv a1, a2
169 ; RV32-NEXT: .LBB8_2:
170 ; RV32-NEXT: mv a0, a1
173 ; RV64-LABEL: icmpasreq:
175 ; RV64-NEXT: sext.w a3, a0
176 ; RV64-NEXT: mv a0, a1
177 ; RV64-NEXT: bltz a3, .LBB8_2
178 ; RV64-NEXT: # %bb.1:
179 ; RV64-NEXT: mv a0, a2
180 ; RV64-NEXT: .LBB8_2:
182 %sh = ashr i32 %input, 31
183 %c = icmp eq i32 %sh, -1
184 %s = select i1 %c, i32 %a, i32 %b
188 define i32 @icmpasrne(i32 %input, i32 %a, i32 %b) {
189 ; RV32-LABEL: icmpasrne:
191 ; RV32-NEXT: bgez a0, .LBB9_2
192 ; RV32-NEXT: # %bb.1:
193 ; RV32-NEXT: mv a1, a2
194 ; RV32-NEXT: .LBB9_2:
195 ; RV32-NEXT: mv a0, a1
198 ; RV64-LABEL: icmpasrne:
200 ; RV64-NEXT: sext.w a3, a0
201 ; RV64-NEXT: mv a0, a1
202 ; RV64-NEXT: bgez a3, .LBB9_2
203 ; RV64-NEXT: # %bb.1:
204 ; RV64-NEXT: mv a0, a2
205 ; RV64-NEXT: .LBB9_2:
207 %sh = ashr i32 %input, 31
208 %c = icmp ne i32 %sh, -1
209 %s = select i1 %c, i32 %a, i32 %b
213 define i32 @oneusecmp(i32 %a, i32 %b, i32 %d) {
214 ; RV32-LABEL: oneusecmp:
216 ; RV32-NEXT: srai a3, a0, 31
217 ; RV32-NEXT: xori a3, a3, 127
218 ; RV32-NEXT: bltz a0, .LBB10_2
219 ; RV32-NEXT: # %bb.1:
220 ; RV32-NEXT: mv a2, a1
221 ; RV32-NEXT: .LBB10_2:
222 ; RV32-NEXT: add a0, a3, a2
225 ; RV64-LABEL: oneusecmp:
227 ; RV64-NEXT: sext.w a3, a0
228 ; RV64-NEXT: sraiw a0, a0, 31
229 ; RV64-NEXT: xori a0, a0, 127
230 ; RV64-NEXT: bltz a3, .LBB10_2
231 ; RV64-NEXT: # %bb.1:
232 ; RV64-NEXT: mv a2, a1
233 ; RV64-NEXT: .LBB10_2:
234 ; RV64-NEXT: addw a0, a0, a2
236 %c = icmp sle i32 %a, -1
237 %s = select i1 %c, i32 -128, i32 127
238 %s2 = select i1 %c, i32 %d, i32 %b