1 # NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2 # RUN: llc -mtriple aarch64-unknown-unknown -run-pass=instruction-select -verify-machineinstrs %s -o - | FileCheck %s
4 # Verify that we can fold G_AND into G_BRCOND when all of the following hold:
5 # 1. We have a ne/eq G_ICMP feeding into the G_BRCOND
6 # 2. The G_ICMP is being compared against 0
7 # 3. One of the operands of the G_AND is a power of 2
9 # If all of these hold, we should produce a tbnz or a tbz.
17 ; CHECK-LABEL: name: tbnzx_and
19 ; CHECK-NEXT: successors: %bb.0(0x40000000), %bb.1(0x40000000)
20 ; CHECK-NEXT: liveins: $x0
22 ; CHECK-NEXT: [[COPY:%[0-9]+]]:gpr64 = COPY $x0
23 ; CHECK-NEXT: TBNZX [[COPY]], 33, %bb.1
27 ; CHECK-NEXT: RET_ReallyLR
29 successors: %bb.0, %bb.1
31 %0:gpr(s64) = COPY $x0
32 %1:gpr(s64) = G_CONSTANT i64 8589934592 ; Bit number 33 => TBNZX
33 %3:gpr(s64) = G_CONSTANT i64 0
34 %2:gpr(s64) = G_AND %0, %1
35 %5:gpr(s32) = G_ICMP intpred(ne), %2(s64), %3
47 tracksRegLiveness: true
49 ; CHECK-LABEL: name: tbzx_and
51 ; CHECK-NEXT: successors: %bb.0(0x40000000), %bb.1(0x40000000)
52 ; CHECK-NEXT: liveins: $x0
54 ; CHECK-NEXT: [[COPY:%[0-9]+]]:gpr64 = COPY $x0
55 ; CHECK-NEXT: TBZX [[COPY]], 33, %bb.1
59 ; CHECK-NEXT: RET_ReallyLR
61 successors: %bb.0, %bb.1
63 %0:gpr(s64) = COPY $x0
64 %1:gpr(s64) = G_CONSTANT i64 8589934592 ; Bit number 33 => TBNZX
65 %3:gpr(s64) = G_CONSTANT i64 0
66 %2:gpr(s64) = G_AND %0, %1
67 %5:gpr(s32) = G_ICMP intpred(eq), %2(s64), %3
79 tracksRegLiveness: true
81 ; CHECK-LABEL: name: tbnzw_and
83 ; CHECK-NEXT: successors: %bb.0(0x40000000), %bb.1(0x40000000)
84 ; CHECK-NEXT: liveins: $w0
86 ; CHECK-NEXT: [[COPY:%[0-9]+]]:gpr32 = COPY $w0
87 ; CHECK-NEXT: TBNZW [[COPY]], 0, %bb.1
91 ; CHECK-NEXT: RET_ReallyLR
93 successors: %bb.0, %bb.1
95 %0:gpr(s32) = COPY $w0
96 %1:gpr(s32) = G_CONSTANT i32 1
97 %3:gpr(s32) = G_CONSTANT i32 0
98 %2:gpr(s32) = G_AND %0, %1
99 %5:gpr(s32) = G_ICMP intpred(ne), %2(s32), %3
110 regBankSelected: true
111 tracksRegLiveness: true
113 ; CHECK-LABEL: name: tbzw_and
115 ; CHECK-NEXT: successors: %bb.0(0x40000000), %bb.1(0x40000000)
116 ; CHECK-NEXT: liveins: $w0
118 ; CHECK-NEXT: [[COPY:%[0-9]+]]:gpr32 = COPY $w0
119 ; CHECK-NEXT: TBZW [[COPY]], 0, %bb.1
120 ; CHECK-NEXT: B %bb.0
123 ; CHECK-NEXT: RET_ReallyLR
125 successors: %bb.0, %bb.1
127 %0:gpr(s32) = COPY $w0
128 %1:gpr(s32) = G_CONSTANT i32 1
129 %3:gpr(s32) = G_CONSTANT i32 0
130 %2:gpr(s32) = G_AND %0, %1
131 %5:gpr(s32) = G_ICMP intpred(eq), %2(s32), %3
139 name: dont_fold_and_lt
142 regBankSelected: true
143 tracksRegLiveness: true
145 ; CHECK-LABEL: name: dont_fold_and_lt
147 ; CHECK-NEXT: successors: %bb.0(0x40000000), %bb.1(0x40000000)
148 ; CHECK-NEXT: liveins: $w0
150 ; CHECK-NEXT: [[COPY:%[0-9]+]]:gpr32 = COPY $w0
151 ; CHECK-NEXT: [[ANDSWri:%[0-9]+]]:gpr32 = ANDSWri [[COPY]], 0, implicit-def $nzcv
152 ; CHECK-NEXT: Bcc 11, %bb.1, implicit $nzcv
153 ; CHECK-NEXT: B %bb.0
156 ; CHECK-NEXT: RET_ReallyLR
158 successors: %bb.0, %bb.1
160 %0:gpr(s32) = COPY $w0
161 %1:gpr(s32) = G_CONSTANT i32 1
162 %3:gpr(s32) = G_CONSTANT i32 0
163 %2:gpr(s32) = G_AND %0, %1
164 %5:gpr(s32) = G_ICMP intpred(slt), %2(s32), %3
172 name: dont_fold_and_gt
175 regBankSelected: true
176 tracksRegLiveness: true
178 ; CHECK-LABEL: name: dont_fold_and_gt
180 ; CHECK-NEXT: successors: %bb.0(0x40000000), %bb.1(0x40000000)
181 ; CHECK-NEXT: liveins: $w0
183 ; CHECK-NEXT: [[COPY:%[0-9]+]]:gpr32 = COPY $w0
184 ; CHECK-NEXT: [[ANDSWri:%[0-9]+]]:gpr32 = ANDSWri [[COPY]], 0, implicit-def $nzcv
185 ; CHECK-NEXT: Bcc 12, %bb.1, implicit $nzcv
186 ; CHECK-NEXT: B %bb.0
189 ; CHECK-NEXT: RET_ReallyLR
191 successors: %bb.0, %bb.1
193 %0:gpr(s32) = COPY $w0
194 %1:gpr(s32) = G_CONSTANT i32 1
195 %3:gpr(s32) = G_CONSTANT i32 0
196 %2:gpr(s32) = G_AND %0, %1
197 %5:gpr(s32) = G_ICMP intpred(sgt), %2(s32), %3
205 name: dont_fold_and_not_power_of_2
208 regBankSelected: true
210 ; CHECK-LABEL: name: dont_fold_and_not_power_of_2
212 ; CHECK-NEXT: successors: %bb.0(0x40000000), %bb.1(0x40000000)
213 ; CHECK-NEXT: liveins: $x0
215 ; CHECK-NEXT: [[COPY:%[0-9]+]]:gpr64 = COPY $x0
216 ; CHECK-NEXT: [[ANDXri:%[0-9]+]]:gpr64common = ANDXri [[COPY]], 4098
217 ; CHECK-NEXT: CBNZX [[ANDXri]], %bb.1
218 ; CHECK-NEXT: B %bb.0
221 ; CHECK-NEXT: RET_ReallyLR
223 successors: %bb.0, %bb.1
225 %0:gpr(s64) = COPY $x0
226 %1:gpr(s64) = G_CONSTANT i64 7
227 %3:gpr(s64) = G_CONSTANT i64 0
228 %2:gpr(s64) = G_AND %0, %1
229 %5:gpr(s32) = G_ICMP intpred(ne), %2(s64), %3
237 name: dont_fold_cmp_not_0
240 regBankSelected: true
242 ; CHECK-LABEL: name: dont_fold_cmp_not_0
244 ; CHECK-NEXT: successors: %bb.0(0x40000000), %bb.1(0x40000000)
245 ; CHECK-NEXT: liveins: $x0
247 ; CHECK-NEXT: [[COPY:%[0-9]+]]:gpr64 = COPY $x0
248 ; CHECK-NEXT: [[ANDXri:%[0-9]+]]:gpr64sp = ANDXri [[COPY]], 8064
249 ; CHECK-NEXT: [[SUBSXri:%[0-9]+]]:gpr64 = SUBSXri [[ANDXri]], 4, 0, implicit-def $nzcv
250 ; CHECK-NEXT: Bcc 1, %bb.1, implicit $nzcv
251 ; CHECK-NEXT: B %bb.0
254 ; CHECK-NEXT: RET_ReallyLR
256 successors: %bb.0, %bb.1
258 %0:gpr(s64) = COPY $x0
259 %1:gpr(s64) = G_CONSTANT i64 4
260 %3:gpr(s64) = G_CONSTANT i64 4
261 %2:gpr(s64) = G_AND %0, %1
262 %5:gpr(s32) = G_ICMP intpred(ne), %2(s64), %3