1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
3 ; RUN: | FileCheck %s -check-prefix=RV32I
4 ; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
5 ; RUN: | FileCheck %s -check-prefix=RV64I
7 define i32 @shl_by_complemented_32(i32 %x) {
8 ; RV32I-LABEL: shl_by_complemented_32:
10 ; RV32I-NEXT: not a1, a0
11 ; RV32I-NEXT: sll a0, a0, a1
14 ; RV64I-LABEL: shl_by_complemented_32:
16 ; RV64I-NEXT: not a1, a0
17 ; RV64I-NEXT: sllw a0, a0, a1
24 define i64 @shl_by_complemented_64(i64 %x) {
25 ; RV32I-LABEL: shl_by_complemented_64:
27 ; RV32I-NEXT: not a4, a0
28 ; RV32I-NEXT: li a2, 31
29 ; RV32I-NEXT: sub a2, a2, a0
30 ; RV32I-NEXT: sll a3, a0, a4
31 ; RV32I-NEXT: bltz a2, .LBB1_2
32 ; RV32I-NEXT: # %bb.1:
33 ; RV32I-NEXT: mv a1, a3
34 ; RV32I-NEXT: j .LBB1_3
35 ; RV32I-NEXT: .LBB1_2:
36 ; RV32I-NEXT: sll a1, a1, a4
37 ; RV32I-NEXT: li a4, 63
38 ; RV32I-NEXT: sub a4, a4, a0
39 ; RV32I-NEXT: not a4, a4
40 ; RV32I-NEXT: srli a0, a0, 1
41 ; RV32I-NEXT: srl a0, a0, a4
42 ; RV32I-NEXT: or a1, a1, a0
43 ; RV32I-NEXT: .LBB1_3:
44 ; RV32I-NEXT: srai a0, a2, 31
45 ; RV32I-NEXT: and a0, a0, a3
48 ; RV64I-LABEL: shl_by_complemented_64:
50 ; RV64I-NEXT: not a1, a0
51 ; RV64I-NEXT: sll a0, a0, a1
58 define i32 @lshr_by_complemented_32(i32 %x) {
59 ; RV32I-LABEL: lshr_by_complemented_32:
61 ; RV32I-NEXT: not a1, a0
62 ; RV32I-NEXT: srl a0, a0, a1
65 ; RV64I-LABEL: lshr_by_complemented_32:
67 ; RV64I-NEXT: not a1, a0
68 ; RV64I-NEXT: srlw a0, a0, a1
75 define i64 @lshr_by_complemented_64(i64 %x) {
76 ; RV32I-LABEL: lshr_by_complemented_64:
78 ; RV32I-NEXT: not a4, a0
79 ; RV32I-NEXT: li a2, 31
80 ; RV32I-NEXT: sub a2, a2, a0
81 ; RV32I-NEXT: srl a3, a1, a4
82 ; RV32I-NEXT: bltz a2, .LBB3_2
83 ; RV32I-NEXT: # %bb.1:
84 ; RV32I-NEXT: mv a0, a3
85 ; RV32I-NEXT: j .LBB3_3
86 ; RV32I-NEXT: .LBB3_2:
87 ; RV32I-NEXT: srl a4, a0, a4
88 ; RV32I-NEXT: li a5, 63
89 ; RV32I-NEXT: sub a5, a5, a0
90 ; RV32I-NEXT: not a0, a5
91 ; RV32I-NEXT: slli a1, a1, 1
92 ; RV32I-NEXT: sll a0, a1, a0
93 ; RV32I-NEXT: or a0, a4, a0
94 ; RV32I-NEXT: .LBB3_3:
95 ; RV32I-NEXT: srai a1, a2, 31
96 ; RV32I-NEXT: and a1, a1, a3
99 ; RV64I-LABEL: lshr_by_complemented_64:
101 ; RV64I-NEXT: not a1, a0
102 ; RV64I-NEXT: srl a0, a0, a1
109 define i32 @ashr_by_complemented_32(i32 %x) {
110 ; RV32I-LABEL: ashr_by_complemented_32:
112 ; RV32I-NEXT: not a1, a0
113 ; RV32I-NEXT: sra a0, a0, a1
116 ; RV64I-LABEL: ashr_by_complemented_32:
118 ; RV64I-NEXT: not a1, a0
119 ; RV64I-NEXT: sraw a0, a0, a1
126 define i64 @ashr_by_complemented_64(i64 %x) {
127 ; RV32I-LABEL: ashr_by_complemented_64:
129 ; RV32I-NEXT: mv a2, a0
130 ; RV32I-NEXT: li a0, 31
131 ; RV32I-NEXT: sub a4, a0, a2
132 ; RV32I-NEXT: not a3, a2
133 ; RV32I-NEXT: sra a0, a1, a3
134 ; RV32I-NEXT: bltz a4, .LBB5_2
135 ; RV32I-NEXT: # %bb.1:
136 ; RV32I-NEXT: srai a1, a1, 31
138 ; RV32I-NEXT: .LBB5_2:
139 ; RV32I-NEXT: srl a3, a2, a3
140 ; RV32I-NEXT: li a4, 63
141 ; RV32I-NEXT: sub a4, a4, a2
142 ; RV32I-NEXT: not a2, a4
143 ; RV32I-NEXT: slli a1, a1, 1
144 ; RV32I-NEXT: sll a1, a1, a2
145 ; RV32I-NEXT: or a3, a3, a1
146 ; RV32I-NEXT: mv a1, a0
147 ; RV32I-NEXT: mv a0, a3
150 ; RV64I-LABEL: ashr_by_complemented_64:
152 ; RV64I-NEXT: not a1, a0
153 ; RV64I-NEXT: sra a0, a0, a1
160 define i32 @shl_by_masked_complemented_32(i32 %x) {
161 ; RV32I-LABEL: shl_by_masked_complemented_32:
163 ; RV32I-NEXT: not a1, a0
164 ; RV32I-NEXT: sll a0, a0, a1
167 ; RV64I-LABEL: shl_by_masked_complemented_32:
169 ; RV64I-NEXT: not a1, a0
170 ; RV64I-NEXT: sllw a0, a0, a1
178 define i64 @shl_by_masked_complemented_64(i64 %x) {
179 ; RV32I-LABEL: shl_by_masked_complemented_64:
181 ; RV32I-NEXT: li a2, 63
182 ; RV32I-NEXT: sub a2, a2, a0
183 ; RV32I-NEXT: andi a4, a2, 63
184 ; RV32I-NEXT: addi a2, a4, -32
185 ; RV32I-NEXT: not a3, a0
186 ; RV32I-NEXT: bltz a2, .LBB7_2
187 ; RV32I-NEXT: # %bb.1:
188 ; RV32I-NEXT: sll a1, a0, a4
189 ; RV32I-NEXT: j .LBB7_3
190 ; RV32I-NEXT: .LBB7_2:
191 ; RV32I-NEXT: sll a1, a1, a3
192 ; RV32I-NEXT: not a4, a4
193 ; RV32I-NEXT: srli a5, a0, 1
194 ; RV32I-NEXT: srl a4, a5, a4
195 ; RV32I-NEXT: or a1, a1, a4
196 ; RV32I-NEXT: .LBB7_3:
197 ; RV32I-NEXT: sll a0, a0, a3
198 ; RV32I-NEXT: srai a2, a2, 31
199 ; RV32I-NEXT: and a0, a2, a0
202 ; RV64I-LABEL: shl_by_masked_complemented_64:
204 ; RV64I-NEXT: not a1, a0
205 ; RV64I-NEXT: sll a0, a0, a1
213 define i64 @lshr_by_masked_complemented_64(i64 %x) {
214 ; RV32I-LABEL: lshr_by_masked_complemented_64:
216 ; RV32I-NEXT: li a2, 63
217 ; RV32I-NEXT: sub a2, a2, a0
218 ; RV32I-NEXT: andi a4, a2, 63
219 ; RV32I-NEXT: addi a2, a4, -32
220 ; RV32I-NEXT: not a3, a0
221 ; RV32I-NEXT: bltz a2, .LBB8_2
222 ; RV32I-NEXT: # %bb.1:
223 ; RV32I-NEXT: srl a0, a1, a4
224 ; RV32I-NEXT: j .LBB8_3
225 ; RV32I-NEXT: .LBB8_2:
226 ; RV32I-NEXT: srl a0, a0, a3
227 ; RV32I-NEXT: not a4, a4
228 ; RV32I-NEXT: slli a5, a1, 1
229 ; RV32I-NEXT: sll a4, a5, a4
230 ; RV32I-NEXT: or a0, a0, a4
231 ; RV32I-NEXT: .LBB8_3:
232 ; RV32I-NEXT: srl a1, a1, a3
233 ; RV32I-NEXT: srai a2, a2, 31
234 ; RV32I-NEXT: and a1, a2, a1
237 ; RV64I-LABEL: lshr_by_masked_complemented_64:
239 ; RV64I-NEXT: not a1, a0
240 ; RV64I-NEXT: srl a0, a0, a1
248 define i64 @ashr_by_masked_complemented_64(i64 %x) {
249 ; RV32I-LABEL: ashr_by_masked_complemented_64:
251 ; RV32I-NEXT: li a2, 63
252 ; RV32I-NEXT: sub a2, a2, a0
253 ; RV32I-NEXT: andi a3, a2, 63
254 ; RV32I-NEXT: addi a4, a3, -32
255 ; RV32I-NEXT: mv a2, a1
256 ; RV32I-NEXT: bltz a4, .LBB9_2
257 ; RV32I-NEXT: # %bb.1:
258 ; RV32I-NEXT: srai a1, a2, 31
259 ; RV32I-NEXT: sra a0, a2, a3
261 ; RV32I-NEXT: .LBB9_2:
262 ; RV32I-NEXT: not a4, a0
263 ; RV32I-NEXT: sra a1, a2, a4
264 ; RV32I-NEXT: srl a0, a0, a4
265 ; RV32I-NEXT: not a3, a3
266 ; RV32I-NEXT: slli a2, a2, 1
267 ; RV32I-NEXT: sll a2, a2, a3
268 ; RV32I-NEXT: or a0, a0, a2
271 ; RV64I-LABEL: ashr_by_masked_complemented_64:
273 ; RV64I-NEXT: not a1, a0
274 ; RV64I-NEXT: sra a0, a0, a1