1 # NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2 # RUN: llc -O0 -mtriple=aarch64-apple-ios -run-pass=localizer -verify-machineinstrs %s -o - | FileCheck %s -check-prefix=CHECK
7 target datalayout = "e-m:o-i64:64-i128:128-n32:64-S128"
9 define void @local_use() { ret void }
10 define void @non_local_1use() { ret void }
11 define void @non_local_2uses() { ret void }
12 define void @non_local_phi_use() { ret void }
13 define void @non_local_phi_use_followed_by_use() { ret void }
14 define void @non_local_phi_use_followed_by_use_fi() { ret void }
15 define void @float_non_local_phi_use_followed_by_use_fi() { ret void }
16 define void @non_local_phi() { ret void }
17 define void @non_local_label() { ret void }
19 @var1 = common global i32 0, align 4
20 @var2 = common global i32 0, align 4
21 @var3 = common global i32 0, align 4
22 @var4 = common global i32 0, align 4
24 define i32 @intrablock_with_globalvalue() {
26 %0 = load i32, i32* @var1, align 4
27 %cmp = icmp eq i32 %0, 1
28 br i1 %cmp, label %if.then, label %if.end
31 store i32 2, i32* @var2, align 4
32 store i32 3, i32* @var1, align 4
33 store i32 2, i32* @var3, align 4
34 store i32 3, i32* @var1, align 4
41 define void @test_inttoptr() { ret void }
51 ; CHECK-LABEL: name: local_use
52 ; CHECK: [[C:%[0-9]+]]:gpr(s32) = G_CONSTANT i32 1
53 ; CHECK: [[ADD:%[0-9]+]]:gpr(s32) = G_ADD [[C]], [[C]]
54 %0:gpr(s32) = G_CONSTANT i32 1
55 %1:gpr(s32) = G_ADD %0, %0
63 ; CHECK-LABEL: name: non_local_1use
65 ; CHECK: successors: %bb.1(0x80000000)
66 ; CHECK: [[C:%[0-9]+]]:gpr(s32) = G_CONSTANT i32 1
67 ; CHECK: [[ADD:%[0-9]+]]:gpr(s32) = G_ADD [[C]], [[C]]
69 ; CHECK: [[C1:%[0-9]+]]:gpr(s32) = G_CONSTANT i32 1
70 ; CHECK: [[ADD1:%[0-9]+]]:gpr(s32) = G_ADD [[C1]], [[ADD]]
72 ; Existing registers should be left untouched
73 ; The newly created reg should be on the same regbank/regclass as its origin.
78 %0:gpr(s32) = G_CONSTANT i32 1
79 %1:gpr(s32) = G_ADD %0, %0
82 %2:gpr(s32) = G_ADD %0, %1
90 ; CHECK-LABEL: name: non_local_2uses
92 ; CHECK: successors: %bb.1(0x80000000)
93 ; CHECK: [[C:%[0-9]+]]:gpr(s32) = G_CONSTANT i32 1
94 ; CHECK: [[ADD:%[0-9]+]]:gpr(s32) = G_ADD [[C]], [[C]]
96 ; CHECK: [[C1:%[0-9]+]]:gpr(s32) = G_CONSTANT i32 1
97 ; CHECK: [[ADD1:%[0-9]+]]:gpr(s32) = G_ADD [[C1]], [[C1]]
99 ; Existing registers should be left untouched
100 ; The newly created reg should be on the same regbank/regclass as its origin.
105 %0:gpr(s32) = G_CONSTANT i32 1
106 %1:gpr(s32) = G_ADD %0, %0
109 %2:gpr(s32) = G_ADD %0, %0
113 name: non_local_phi_use
115 regBankSelected: true
116 tracksRegLiveness: true
118 ; CHECK-LABEL: name: non_local_phi_use
120 ; CHECK: successors: %bb.1(0x80000000)
121 ; CHECK: [[C:%[0-9]+]]:gpr(s32) = G_CONSTANT i32 1
122 ; CHECK: [[ADD:%[0-9]+]]:gpr(s32) = G_ADD [[C]], [[C]]
124 ; CHECK: successors: %bb.2(0x80000000)
125 ; CHECK: [[C1:%[0-9]+]]:gpr(s32) = G_CONSTANT i32 1
127 ; CHECK: [[PHI:%[0-9]+]]:gpr(s32) = PHI [[C1]](s32), %bb.1
128 ; CHECK: [[ADD1:%[0-9]+]]:gpr(s32) = G_ADD [[PHI]], [[PHI]]
130 ; Existing registers should be left untouched
131 ; The newly created reg should be on the same regbank/regclass as its origin.
136 %0:gpr(s32) = G_CONSTANT i32 1
137 %1:gpr(s32) = G_ADD %0, %0
143 %3:gpr(s32) = PHI %0(s32), %bb.1
144 %2:gpr(s32) = G_ADD %3, %3
148 name: non_local_phi_use_followed_by_use
150 regBankSelected: true
151 tracksRegLiveness: true
153 ; CHECK-LABEL: name: non_local_phi_use_followed_by_use
155 ; CHECK: successors: %bb.1(0x80000000)
156 ; CHECK: [[C:%[0-9]+]]:gpr(s32) = G_CONSTANT i32 1
157 ; CHECK: [[ADD:%[0-9]+]]:gpr(s32) = G_ADD [[C]], [[C]]
159 ; CHECK: successors: %bb.2(0x80000000)
160 ; CHECK: [[C1:%[0-9]+]]:gpr(s32) = G_CONSTANT i32 1
162 ; CHECK: [[PHI:%[0-9]+]]:gpr(s32) = PHI [[C1]](s32), %bb.1
163 ; CHECK: [[C2:%[0-9]+]]:gpr(s32) = G_CONSTANT i32 1
164 ; CHECK: [[ADD1:%[0-9]+]]:gpr(s32) = G_ADD [[PHI]], [[C2]]
166 ; Existing registers should be left untouched
167 ; The newly created reg should be on the same regbank/regclass as its origin.
172 %0:gpr(s32) = G_CONSTANT i32 1
173 %1:gpr(s32) = G_ADD %0, %0
179 %3:gpr(s32) = PHI %0(s32), %bb.1
180 %2:gpr(s32) = G_ADD %3, %0
184 name: non_local_phi_use_followed_by_use_fi
186 regBankSelected: true
187 tracksRegLiveness: true
189 ; CHECK-LABEL: name: non_local_phi_use_followed_by_use_fi
191 ; CHECK: successors: %bb.1(0x80000000)
192 ; CHECK: [[FRAME_INDEX:%[0-9]+]]:gpr(s32) = G_FRAME_INDEX 1
193 ; CHECK: [[ADD:%[0-9]+]]:gpr(s32) = G_ADD [[FRAME_INDEX]], [[FRAME_INDEX]]
195 ; CHECK: successors: %bb.2(0x80000000)
196 ; CHECK: [[FRAME_INDEX1:%[0-9]+]]:gpr(s32) = G_FRAME_INDEX 1
198 ; CHECK: [[PHI:%[0-9]+]]:gpr(s32) = PHI [[FRAME_INDEX1]](s32), %bb.1
199 ; CHECK: [[FRAME_INDEX2:%[0-9]+]]:gpr(s32) = G_FRAME_INDEX 1
200 ; CHECK: [[ADD1:%[0-9]+]]:gpr(s32) = G_ADD [[PHI]], [[FRAME_INDEX2]]
202 ; Existing registers should be left untouched
203 ; The newly created reg should be on the same regbank/regclass as its origin.
208 %0:gpr(s32) = G_FRAME_INDEX 1
209 %1:gpr(s32) = G_ADD %0, %0
215 %3:gpr(s32) = PHI %0(s32), %bb.1
216 %2:gpr(s32) = G_ADD %3, %0
220 name: float_non_local_phi_use_followed_by_use_fi
222 regBankSelected: true
223 tracksRegLiveness: true
225 ; CHECK-LABEL: name: float_non_local_phi_use_followed_by_use_fi
227 ; CHECK: successors: %bb.1(0x80000000)
228 ; CHECK: [[C:%[0-9]+]]:fpr(s32) = G_FCONSTANT float 1.000000e+00
229 ; CHECK: [[FADD:%[0-9]+]]:fpr(s32) = G_FADD [[C]], [[C]]
231 ; CHECK: successors: %bb.2(0x80000000)
232 ; CHECK: [[C1:%[0-9]+]]:fpr(s32) = G_FCONSTANT float 1.000000e+00
234 ; CHECK: [[PHI:%[0-9]+]]:fpr(s32) = PHI [[C1]](s32), %bb.1
235 ; CHECK: [[C2:%[0-9]+]]:fpr(s32) = G_FCONSTANT float 1.000000e+00
236 ; CHECK: [[FADD1:%[0-9]+]]:fpr(s32) = G_FADD [[PHI]], [[C2]]
238 ; Existing registers should be left untouched
239 ; The newly created reg should be on the same regbank/regclass as its origin.
244 %0:fpr(s32) = G_FCONSTANT float 1.0
245 %1:fpr(s32) = G_FADD %0, %0
251 %3:fpr(s32) = PHI %0(s32), %bb.1
252 %2:fpr(s32) = G_FADD %3, %0
256 # Make sure we don't insert a constant before PHIs.
257 # This used to happen for loops of one basic block.
260 regBankSelected: true
261 tracksRegLiveness: true
263 ; CHECK-LABEL: name: non_local_phi
265 ; CHECK: successors: %bb.1(0x80000000)
266 ; CHECK: [[C:%[0-9]+]]:fpr(s32) = G_FCONSTANT float 1.000000e+00
267 ; CHECK: [[FADD:%[0-9]+]]:fpr(s32) = G_FADD [[C]], [[C]]
269 ; CHECK: successors: %bb.1(0x80000000)
270 ; CHECK: [[PHI:%[0-9]+]]:fpr(s32) = PHI [[FADD]](s32), %bb.0, %4(s32), %bb.1
271 ; CHECK: [[C1:%[0-9]+]]:fpr(s32) = G_FCONSTANT float 1.000000e+00
272 ; CHECK: [[FADD1:%[0-9]+]]:fpr(s32) = G_FADD [[PHI]], [[FADD]]
275 ; Existing registers should be left untouched
276 ; The newly created reg should be on the same regbank/regclass as its origin.
281 %0:fpr(s32) = G_FCONSTANT float 1.0
282 %1:fpr(s32) = G_FADD %0, %0
287 %3:fpr(s32) = PHI %1(s32), %bb.0, %0(s32), %bb.1
288 %2:fpr(s32) = G_FADD %3, %1
293 # Make sure we don't insert a constant before EH_LABELs.
294 name: non_local_label
296 regBankSelected: true
297 tracksRegLiveness: true
299 ; CHECK-LABEL: name: non_local_label
301 ; CHECK: successors: %bb.1(0x80000000)
302 ; CHECK: liveins: $s0
303 ; CHECK: [[COPY:%[0-9]+]]:fpr(s32) = COPY $s0
304 ; CHECK: [[C:%[0-9]+]]:fpr(s32) = G_FCONSTANT float 1.000000e+00
306 ; CHECK: successors: %bb.1(0x80000000)
308 ; CHECK: [[C1:%[0-9]+]]:fpr(s32) = G_FCONSTANT float 1.000000e+00
309 ; CHECK: [[FADD:%[0-9]+]]:fpr(s32) = G_FADD [[COPY]], [[C1]]
312 ; Existing registers should be left untouched
313 ; The newly created reg should be on the same regbank/regclass as its origin.
319 %0:fpr(s32) = COPY $s0
320 %1:fpr(s32) = G_FCONSTANT float 1.0
326 %2:fpr(s32) = G_FADD %0, %1
330 name: intrablock_with_globalvalue
332 regBankSelected: true
333 tracksRegLiveness: true
335 ; CHECK-LABEL: name: intrablock_with_globalvalue
337 ; CHECK: successors: %bb.1(0x40000000), %bb.2(0x40000000)
338 ; CHECK: [[GV:%[0-9]+]]:gpr(p0) = G_GLOBAL_VALUE @var1
339 ; CHECK: [[C:%[0-9]+]]:gpr(s32) = G_CONSTANT i32 1
340 ; CHECK: [[C1:%[0-9]+]]:gpr(s32) = G_CONSTANT i32 2
341 ; CHECK: [[GV1:%[0-9]+]]:gpr(p0) = G_GLOBAL_VALUE @var2
342 ; CHECK: [[C2:%[0-9]+]]:gpr(s32) = G_CONSTANT i32 3
343 ; CHECK: [[GV2:%[0-9]+]]:gpr(p0) = G_GLOBAL_VALUE @var3
344 ; CHECK: [[C3:%[0-9]+]]:gpr(s32) = G_CONSTANT i32 0
345 ; CHECK: [[LOAD:%[0-9]+]]:gpr(s32) = G_LOAD [[GV]](p0) :: (load 4 from @var1)
346 ; CHECK: [[ICMP:%[0-9]+]]:gpr(s32) = G_ICMP intpred(eq), [[LOAD]](s32), [[C]]
347 ; CHECK: [[TRUNC:%[0-9]+]]:gpr(s1) = G_TRUNC [[ICMP]](s32)
348 ; CHECK: G_BRCOND [[TRUNC]](s1), %bb.1
350 ; CHECK: bb.1.if.then:
351 ; CHECK: successors: %bb.2(0x80000000)
352 ; CHECK: [[GV3:%[0-9]+]]:gpr(p0) = G_GLOBAL_VALUE @var2
353 ; CHECK: [[C4:%[0-9]+]]:gpr(s32) = G_CONSTANT i32 2
354 ; CHECK: G_STORE [[C4]](s32), [[GV3]](p0) :: (store 4 into @var2)
355 ; CHECK: [[C5:%[0-9]+]]:gpr(s32) = G_CONSTANT i32 3
356 ; CHECK: [[GV4:%[0-9]+]]:gpr(p0) = G_GLOBAL_VALUE @var1
357 ; CHECK: G_STORE [[C5]](s32), [[GV4]](p0) :: (store 4 into @var1)
358 ; CHECK: [[GV5:%[0-9]+]]:gpr(p0) = G_GLOBAL_VALUE @var3
359 ; CHECK: G_STORE [[C4]](s32), [[GV5]](p0) :: (store 4 into @var3)
360 ; CHECK: G_STORE [[C5]](s32), [[GV4]](p0) :: (store 4 into @var1)
361 ; CHECK: bb.2.if.end:
362 ; CHECK: [[C6:%[0-9]+]]:gpr(s32) = G_CONSTANT i32 0
363 ; CHECK: $w0 = COPY [[C6]](s32)
364 ; CHECK: RET_ReallyLR implicit $w0
366 ; Some of these instructions are dead. We're checking that the other instructions are
367 ; sunk immediately before their first user in the if.then block or as close as possible.
369 %1:gpr(p0) = G_GLOBAL_VALUE @var1
370 %2:gpr(s32) = G_CONSTANT i32 1
371 %4:gpr(s32) = G_CONSTANT i32 2
372 %5:gpr(p0) = G_GLOBAL_VALUE @var2
373 %6:gpr(s32) = G_CONSTANT i32 3
374 %7:gpr(p0) = G_GLOBAL_VALUE @var3
375 %8:gpr(s32) = G_CONSTANT i32 0
376 %0:gpr(s32) = G_LOAD %1(p0) :: (load 4 from @var1)
377 %9:gpr(s32) = G_ICMP intpred(eq), %0(s32), %2
378 %3:gpr(s1) = G_TRUNC %9(s32)
379 G_BRCOND %3(s1), %bb.2
383 G_STORE %4(s32), %5(p0) :: (store 4 into @var2)
384 G_STORE %6(s32), %1(p0) :: (store 4 into @var1)
385 G_STORE %4(s32), %7(p0) :: (store 4 into @var3)
386 G_STORE %6(s32), %1(p0) :: (store 4 into @var1)
390 RET_ReallyLR implicit $w0
397 regBankSelected: true
398 tracksRegLiveness: true
400 ; CHECK-LABEL: name: test_inttoptr
402 ; CHECK: successors: %bb.1(0x40000000), %bb.2(0x40000000)
403 ; CHECK: liveins: $w0, $x1
404 ; CHECK: [[COPY:%[0-9]+]]:gpr(s32) = COPY $w0
405 ; CHECK: [[COPY1:%[0-9]+]]:gpr(p0) = COPY $x1
406 ; CHECK: [[C:%[0-9]+]]:gpr(s64) = G_CONSTANT i64 128
407 ; CHECK: [[C1:%[0-9]+]]:gpr(s32) = G_CONSTANT i32 0
408 ; CHECK: [[C2:%[0-9]+]]:gpr(s64) = G_CONSTANT i64 0
409 ; CHECK: [[INTTOPTR:%[0-9]+]]:gpr(p0) = G_INTTOPTR [[C2]](s64)
410 ; CHECK: [[INTTOPTR1:%[0-9]+]]:gpr(p0) = G_INTTOPTR [[C]](s64)
411 ; CHECK: [[ICMP:%[0-9]+]]:gpr(s32) = G_ICMP intpred(eq), [[COPY]](s32), [[C1]]
412 ; CHECK: [[TRUNC:%[0-9]+]]:gpr(s1) = G_TRUNC [[ICMP]](s32)
413 ; CHECK: G_BRCOND [[TRUNC]](s1), %bb.1
416 ; CHECK: [[ADD:%[0-9]+]]:gpr(s32) = G_ADD [[COPY]], [[COPY]]
417 ; CHECK: G_STORE [[ADD]](s32), [[COPY1]](p0) :: (store 4)
418 ; CHECK: [[C3:%[0-9]+]]:gpr(s64) = G_CONSTANT i64 128
419 ; CHECK: [[INTTOPTR2:%[0-9]+]]:gpr(p0) = G_INTTOPTR [[C3]](s64)
420 ; CHECK: $x0 = COPY [[INTTOPTR2]](p0)
421 ; CHECK: RET_ReallyLR implicit $x0
423 ; CHECK: [[C4:%[0-9]+]]:gpr(s64) = G_CONSTANT i64 0
424 ; CHECK: [[INTTOPTR3:%[0-9]+]]:gpr(p0) = G_INTTOPTR [[C4]](s64)
425 ; CHECK: $x0 = COPY [[INTTOPTR3]](p0)
426 ; CHECK: RET_ReallyLR implicit $x0
430 %0:gpr(s32) = COPY $w0
431 %1:gpr(p0) = COPY $x1
432 %2:gpr(s64) = G_CONSTANT i64 128
433 %4:gpr(s32) = G_CONSTANT i32 0
434 %7:gpr(s64) = G_CONSTANT i64 0
435 %6:gpr(p0) = G_INTTOPTR %7(s64)
436 %3:gpr(p0) = G_INTTOPTR %2(s64)
437 %9:gpr(s32) = G_ICMP intpred(eq), %0(s32), %4
438 %5:gpr(s1) = G_TRUNC %9(s32)
439 G_BRCOND %5(s1), %bb.2
443 %8:gpr(s32) = G_ADD %0, %0
444 G_STORE %8(s32), %1(p0) :: (store 4)
446 RET_ReallyLR implicit $x0
450 RET_ReallyLR implicit $x0