1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=riscv32 | FileCheck %s --check-prefixes=RV32
3 ; RUN: llc < %s -mtriple=riscv64 | FileCheck %s --check-prefixes=RV64
5 define signext i32 @test1(i32 signext %x) nounwind {
8 ; RV32-NEXT: ori a0, a0, 31
9 ; RV32-NEXT: slli a0, a0, 10
14 ; RV64-NEXT: ori a0, a0, 31
15 ; RV64-NEXT: slliw a0, a0, 10
18 %shl = or i32 %or, 31744
22 define signext i32 @test2(i32 signext %x) nounwind {
25 ; RV32-NEXT: xori a0, a0, 31
26 ; RV32-NEXT: slli a0, a0, 10
31 ; RV64-NEXT: xori a0, a0, 31
32 ; RV64-NEXT: slliw a0, a0, 10
35 %shl = xor i32 %xor, 31744
39 define i64 @test3(i64 %x) nounwind {
42 ; RV32-NEXT: andi a1, a0, 241
43 ; RV32-NEXT: slli a1, a1, 8
49 ; RV64-NEXT: andi a0, a0, 241
50 ; RV64-NEXT: slli a0, a0, 40
53 %shl = and i64 %and, 264982302294016
57 define i64 @test4(i64 %x) nounwind {
60 ; RV32-NEXT: ori a1, a0, 241
61 ; RV32-NEXT: slli a1, a1, 8
67 ; RV64-NEXT: ori a0, a0, 241
68 ; RV64-NEXT: slli a0, a0, 40
71 %shl = or i64 %or, 264982302294016
75 define i64 @test5(i64 %x) nounwind {
78 ; RV32-NEXT: ori a1, a0, 31
79 ; RV32-NEXT: slli a1, a1, 8
85 ; RV64-NEXT: ori a0, a0, 31
86 ; RV64-NEXT: slli a0, a0, 40
89 %shl = or i64 %or, 34084860461056
93 define i64 @test6(i64 %x) nounwind {
96 ; RV32-NEXT: xori a1, a0, 241
97 ; RV32-NEXT: slli a1, a1, 8
103 ; RV64-NEXT: xori a0, a0, 241
104 ; RV64-NEXT: slli a0, a0, 40
106 %xor = shl i64 %x, 40
107 %shl = xor i64 %xor, 264982302294016
111 define i64 @test7(i64 %x) nounwind {
114 ; RV32-NEXT: xori a1, a0, 31
115 ; RV32-NEXT: slli a1, a1, 8
116 ; RV32-NEXT: li a0, 0
121 ; RV64-NEXT: xori a0, a0, 31
122 ; RV64-NEXT: slli a0, a0, 40
124 %xor = shl i64 %x, 40
125 %shl = xor i64 %xor, 34084860461056
129 define i64 @test8(i64 %x) nounwind {
132 ; RV32-NEXT: slli a0, a0, 1
133 ; RV32-NEXT: andi a1, a0, -482
134 ; RV32-NEXT: li a0, 0
139 ; RV64-NEXT: andi a0, a0, -241
140 ; RV64-NEXT: slli a0, a0, 33
142 %xor = shl i64 %x, 33
143 %shl = and i64 %xor, -2070174236672
147 define i64 @test9(i64 %x) nounwind {
150 ; RV32-NEXT: slli a0, a0, 1
151 ; RV32-NEXT: ori a1, a0, -482
152 ; RV32-NEXT: li a0, 0
157 ; RV64-NEXT: ori a0, a0, -241
158 ; RV64-NEXT: slli a0, a0, 33
160 %xor = shl i64 %x, 33
161 %shl = or i64 %xor, -2070174236672
165 define i64 @test10(i64 %x) nounwind {
166 ; RV32-LABEL: test10:
168 ; RV32-NEXT: slli a0, a0, 1
169 ; RV32-NEXT: xori a1, a0, -482
170 ; RV32-NEXT: li a0, 0
173 ; RV64-LABEL: test10:
175 ; RV64-NEXT: xori a0, a0, -241
176 ; RV64-NEXT: slli a0, a0, 33
178 %xor = shl i64 %x, 33
179 %shl = xor i64 %xor, -2070174236672
183 define signext i32 @test11(i32 signext %x) nounwind {
184 ; RV32-LABEL: test11:
186 ; RV32-NEXT: andi a0, a0, -241
187 ; RV32-NEXT: slli a0, a0, 17
190 ; RV64-LABEL: test11:
192 ; RV64-NEXT: andi a0, a0, -241
193 ; RV64-NEXT: slliw a0, a0, 17
196 %shl = and i32 %or, -31588352
200 define signext i32 @test12(i32 signext %x) nounwind {
201 ; RV32-LABEL: test12:
203 ; RV32-NEXT: ori a0, a0, -241
204 ; RV32-NEXT: slli a0, a0, 17
207 ; RV64-LABEL: test12:
209 ; RV64-NEXT: ori a0, a0, -241
210 ; RV64-NEXT: slli a0, a0, 17
213 %shl = or i32 %or, -31588352
217 define signext i32 @test13(i32 signext %x) nounwind {
218 ; RV32-LABEL: test13:
220 ; RV32-NEXT: xori a0, a0, -241
221 ; RV32-NEXT: slli a0, a0, 17
224 ; RV64-LABEL: test13:
226 ; RV64-NEXT: xori a0, a0, -241
227 ; RV64-NEXT: slliw a0, a0, 17
230 %shl = xor i32 %or, -31588352
234 ; Negative test. Can't transform because the constant has a 1 in the bits
235 ; cleared by the shl.
236 define signext i32 @test14(i32 signext %x) nounwind {
237 ; RV32-LABEL: test14:
239 ; RV32-NEXT: slli a0, a0, 10
240 ; RV32-NEXT: lui a1, 8
241 ; RV32-NEXT: addi a1, a1, -1027
242 ; RV32-NEXT: or a0, a0, a1
245 ; RV64-LABEL: test14:
247 ; RV64-NEXT: slliw a0, a0, 10
248 ; RV64-NEXT: lui a1, 8
249 ; RV64-NEXT: addiw a1, a1, -1027
250 ; RV64-NEXT: or a0, a0, a1
253 %shl = or i32 %or, 31741
257 ; Negative test. Can't transform because the constant has a 1 in the bits
258 ; cleared by the shl.
259 define signext i32 @test15(i32 signext %x) nounwind {
260 ; RV32-LABEL: test15:
262 ; RV32-NEXT: slli a0, a0, 10
263 ; RV32-NEXT: lui a1, 8
264 ; RV32-NEXT: addi a1, a1, -515
265 ; RV32-NEXT: xor a0, a0, a1
268 ; RV64-LABEL: test15:
270 ; RV64-NEXT: slliw a0, a0, 10
271 ; RV64-NEXT: lui a1, 8
272 ; RV64-NEXT: addiw a1, a1, -515
273 ; RV64-NEXT: xor a0, a0, a1
275 %xor = shl i32 %x, 10
276 %shl = xor i32 %xor, 32253