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 ; Test for handling of AND with constant. If this constant exceeds simm12 and
8 ; also is a non-empty sequence of ones starting at the least significant bit
9 ; with the remainder zero, we can replace it with SLLI + SLRI
11 define i32 @and32_0x7ff(i32 %x) {
12 ; RV32I-LABEL: and32_0x7ff:
14 ; RV32I-NEXT: andi a0, a0, 2047
17 ; RV64I-LABEL: and32_0x7ff:
19 ; RV64I-NEXT: andi a0, a0, 2047
25 define i32 @and32_0xfff(i32 %x) {
26 ; RV32I-LABEL: and32_0xfff:
28 ; RV32I-NEXT: slli a0, a0, 20
29 ; RV32I-NEXT: srli a0, a0, 20
32 ; RV64I-LABEL: and32_0xfff:
34 ; RV64I-NEXT: slli a0, a0, 52
35 ; RV64I-NEXT: srli a0, a0, 52
41 define i64 @and64_0x7ff(i64 %x) {
42 ; RV32I-LABEL: and64_0x7ff:
44 ; RV32I-NEXT: andi a0, a0, 2047
45 ; RV32I-NEXT: li a1, 0
48 ; RV64I-LABEL: and64_0x7ff:
50 ; RV64I-NEXT: andi a0, a0, 2047
56 define i64 @and64_0xfff(i64 %x) {
57 ; RV32I-LABEL: and64_0xfff:
59 ; RV32I-NEXT: slli a0, a0, 20
60 ; RV32I-NEXT: srli a0, a0, 20
61 ; RV32I-NEXT: li a1, 0
64 ; RV64I-LABEL: and64_0xfff:
66 ; RV64I-NEXT: slli a0, a0, 52
67 ; RV64I-NEXT: srli a0, a0, 52
73 ; Test for handling of AND with constant. If this constant exceeds simm32 and
74 ; also is a non-empty sequence of ones starting at the most significant bit
75 ; with the remainder zero, we can replace it with SRLI + SLLI.
77 define i32 @and32_0x7ffff000(i32 %x) {
78 ; RV32I-LABEL: and32_0x7ffff000:
80 ; RV32I-NEXT: lui a1, 524287
81 ; RV32I-NEXT: and a0, a0, a1
84 ; RV64I-LABEL: and32_0x7ffff000:
86 ; RV64I-NEXT: lui a1, 524287
87 ; RV64I-NEXT: and a0, a0, a1
89 %a = and i32 %x, 2147479552
93 define i32 @and32_0xfffff000(i32 %x) {
94 ; RV32I-LABEL: and32_0xfffff000:
96 ; RV32I-NEXT: lui a1, 1048575
97 ; RV32I-NEXT: and a0, a0, a1
100 ; RV64I-LABEL: and32_0xfffff000:
102 ; RV64I-NEXT: lui a1, 1048575
103 ; RV64I-NEXT: and a0, a0, a1
105 %a = and i32 %x, -4096
109 define i32 @and32_0xfffffa00(i32 %x) {
110 ; RV32I-LABEL: and32_0xfffffa00:
112 ; RV32I-NEXT: andi a0, a0, -1536
115 ; RV64I-LABEL: and32_0xfffffa00:
117 ; RV64I-NEXT: andi a0, a0, -1536
119 %a = and i32 %x, -1536
123 define i64 @and64_0x7ffffffffffff000(i64 %x) {
124 ; RV32I-LABEL: and64_0x7ffffffffffff000:
126 ; RV32I-NEXT: lui a2, 1048575
127 ; RV32I-NEXT: and a0, a0, a2
128 ; RV32I-NEXT: slli a1, a1, 1
129 ; RV32I-NEXT: srli a1, a1, 1
132 ; RV64I-LABEL: and64_0x7ffffffffffff000:
134 ; RV64I-NEXT: lui a1, 1048574
135 ; RV64I-NEXT: srli a1, a1, 1
136 ; RV64I-NEXT: and a0, a0, a1
138 %a = and i64 %x, 9223372036854771712
142 define i64 @and64_0xfffffffffffff000(i64 %x) {
143 ; RV32I-LABEL: and64_0xfffffffffffff000:
145 ; RV32I-NEXT: lui a2, 1048575
146 ; RV32I-NEXT: and a0, a0, a2
149 ; RV64I-LABEL: and64_0xfffffffffffff000:
151 ; RV64I-NEXT: lui a1, 1048575
152 ; RV64I-NEXT: and a0, a0, a1
154 %a = and i64 %x, -4096
158 define i64 @and64_0xfffffffffffffa00(i64 %x) {
159 ; RV32I-LABEL: and64_0xfffffffffffffa00:
161 ; RV32I-NEXT: andi a0, a0, -1536
164 ; RV64I-LABEL: and64_0xfffffffffffffa00:
166 ; RV64I-NEXT: andi a0, a0, -1536
168 %a = and i64 %x, -1536
172 define i64 @and64_0xffffffff00000000(i64 %x) {
173 ; RV32I-LABEL: and64_0xffffffff00000000:
175 ; RV32I-NEXT: li a0, 0
178 ; RV64I-LABEL: and64_0xffffffff00000000:
180 ; RV64I-NEXT: srli a0, a0, 32
181 ; RV64I-NEXT: slli a0, a0, 32
183 %a = and i64 %x, -4294967296
187 define i64 @and64_0x7fffffff00000000(i64 %x) {
188 ; RV32I-LABEL: and64_0x7fffffff00000000:
190 ; RV32I-NEXT: slli a0, a1, 1
191 ; RV32I-NEXT: srli a1, a0, 1
192 ; RV32I-NEXT: li a0, 0
195 ; RV64I-LABEL: and64_0x7fffffff00000000:
197 ; RV64I-NEXT: lui a1, 524288
198 ; RV64I-NEXT: addiw a1, a1, -1
199 ; RV64I-NEXT: slli a1, a1, 32
200 ; RV64I-NEXT: and a0, a0, a1
202 %a = and i64 %x, 9223372032559808512
206 define i64 @and64_0xffffffff80000000(i64 %x) {
207 ; RV32I-LABEL: and64_0xffffffff80000000:
209 ; RV32I-NEXT: lui a2, 524288
210 ; RV32I-NEXT: and a0, a0, a2
213 ; RV64I-LABEL: and64_0xffffffff80000000:
215 ; RV64I-NEXT: lui a1, 524288
216 ; RV64I-NEXT: and a0, a0, a1
218 %a = and i64 %x, -2147483648