1 ; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 2
2 ; RUN: llc -mtriple=aarch64-apple-ios -global-isel -stop-after=irtranslator %s -o - | FileCheck %s --check-prefix=TRANSLATED
3 ; RUN: llc -mtriple=aarch64-apple-ios -global-isel -stop-before=instruction-select %s -o - | FileCheck %s --check-prefix=PRESELECTION
4 ; RUN: llc -mtriple=aarch64-apple-ios -global-isel -stop-after=instruction-select %s -o - | FileCheck %s --check-prefix=POSTSELECTION
6 ; Check we generate G_CONSTANT_FOLD_BARRIER of constants and don't fold them, since they're
7 ; used by constant hoisting to prevent constant folding/propagation.
11 define i32 @test(i32 %a, i1 %c) {
12 ; TRANSLATED-LABEL: name: test
13 ; TRANSLATED: bb.1.entry:
14 ; TRANSLATED-NEXT: successors: %bb.3(0x40000000), %bb.2(0x40000000)
15 ; TRANSLATED-NEXT: liveins: $w0, $w1
16 ; TRANSLATED-NEXT: {{ $}}
17 ; TRANSLATED-NEXT: [[COPY:%[0-9]+]]:_(s32) = COPY $w0
18 ; TRANSLATED-NEXT: [[COPY1:%[0-9]+]]:_(s32) = COPY $w1
19 ; TRANSLATED-NEXT: [[TRUNC:%[0-9]+]]:_(s8) = G_TRUNC [[COPY1]](s32)
20 ; TRANSLATED-NEXT: [[ASSERT_ZEXT:%[0-9]+]]:_(s8) = G_ASSERT_ZEXT [[TRUNC]], 1
21 ; TRANSLATED-NEXT: [[TRUNC1:%[0-9]+]]:_(s1) = G_TRUNC [[ASSERT_ZEXT]](s8)
22 ; TRANSLATED-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 100000
23 ; TRANSLATED-NEXT: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
24 ; TRANSLATED-NEXT: [[CONSTANT_FOLD_BARRIER:%[0-9]+]]:_(s32) = G_CONSTANT_FOLD_BARRIER [[C]]
25 ; TRANSLATED-NEXT: G_BRCOND [[TRUNC1]](s1), %bb.3
26 ; TRANSLATED-NEXT: G_BR %bb.2
27 ; TRANSLATED-NEXT: {{ $}}
28 ; TRANSLATED-NEXT: bb.2.common.ret:
29 ; TRANSLATED-NEXT: [[PHI:%[0-9]+]]:_(s32) = G_PHI %7(s32), %bb.3, [[C1]](s32), %bb.1
30 ; TRANSLATED-NEXT: $w0 = COPY [[PHI]](s32)
31 ; TRANSLATED-NEXT: RET_ReallyLR implicit $w0
32 ; TRANSLATED-NEXT: {{ $}}
33 ; TRANSLATED-NEXT: bb.3.cont:
34 ; TRANSLATED-NEXT: successors: %bb.2(0x80000000)
35 ; TRANSLATED-NEXT: {{ $}}
36 ; TRANSLATED-NEXT: [[ADD:%[0-9]+]]:_(s32) = G_ADD [[COPY]], [[CONSTANT_FOLD_BARRIER]]
37 ; TRANSLATED-NEXT: ADJCALLSTACKDOWN 0, 0, implicit-def $sp, implicit $sp
38 ; TRANSLATED-NEXT: BL @callee, csr_darwin_aarch64_aapcs, implicit-def $lr, implicit $sp
39 ; TRANSLATED-NEXT: ADJCALLSTACKUP 0, 0, implicit-def $sp, implicit $sp
40 ; TRANSLATED-NEXT: G_BR %bb.2
41 ; PRESELECTION-LABEL: name: test
42 ; PRESELECTION: bb.1.entry:
43 ; PRESELECTION-NEXT: successors: %bb.3(0x40000000), %bb.2(0x40000000)
44 ; PRESELECTION-NEXT: liveins: $w0, $w1
45 ; PRESELECTION-NEXT: {{ $}}
46 ; PRESELECTION-NEXT: [[COPY:%[0-9]+]]:gpr(s32) = COPY $w0
47 ; PRESELECTION-NEXT: [[COPY1:%[0-9]+]]:gpr(s32) = COPY $w1
48 ; PRESELECTION-NEXT: [[TRUNC:%[0-9]+]]:gpr(s8) = G_TRUNC [[COPY1]](s32)
49 ; PRESELECTION-NEXT: [[ASSERT_ZEXT:%[0-9]+]]:gpr(s8) = G_ASSERT_ZEXT [[TRUNC]], 1
50 ; PRESELECTION-NEXT: [[C:%[0-9]+]]:gpr(s32) = G_CONSTANT i32 0
51 ; PRESELECTION-NEXT: [[C1:%[0-9]+]]:gpr(s32) = G_CONSTANT i32 100000
52 ; PRESELECTION-NEXT: [[CONSTANT_FOLD_BARRIER:%[0-9]+]]:gpr(s32) = G_CONSTANT_FOLD_BARRIER [[C1]]
53 ; PRESELECTION-NEXT: [[C2:%[0-9]+]]:gpr(s32) = G_CONSTANT i32 1
54 ; PRESELECTION-NEXT: [[ANYEXT:%[0-9]+]]:gpr(s32) = G_ANYEXT [[ASSERT_ZEXT]](s8)
55 ; PRESELECTION-NEXT: [[AND:%[0-9]+]]:gpr(s32) = G_AND [[ANYEXT]], [[C2]]
56 ; PRESELECTION-NEXT: G_BRCOND [[AND]](s32), %bb.3
57 ; PRESELECTION-NEXT: G_BR %bb.2
58 ; PRESELECTION-NEXT: {{ $}}
59 ; PRESELECTION-NEXT: bb.2.common.ret:
60 ; PRESELECTION-NEXT: [[PHI:%[0-9]+]]:gpr(s32) = G_PHI %7(s32), %bb.3, [[C]](s32), %bb.1
61 ; PRESELECTION-NEXT: $w0 = COPY [[PHI]](s32)
62 ; PRESELECTION-NEXT: RET_ReallyLR implicit $w0
63 ; PRESELECTION-NEXT: {{ $}}
64 ; PRESELECTION-NEXT: bb.3.cont:
65 ; PRESELECTION-NEXT: successors: %bb.2(0x80000000)
66 ; PRESELECTION-NEXT: {{ $}}
67 ; PRESELECTION-NEXT: [[ADD:%[0-9]+]]:gpr(s32) = G_ADD [[COPY]], [[CONSTANT_FOLD_BARRIER]]
68 ; PRESELECTION-NEXT: ADJCALLSTACKDOWN 0, 0, implicit-def $sp, implicit $sp
69 ; PRESELECTION-NEXT: BL @callee, csr_darwin_aarch64_aapcs, implicit-def $lr, implicit $sp
70 ; PRESELECTION-NEXT: ADJCALLSTACKUP 0, 0, implicit-def $sp, implicit $sp
71 ; PRESELECTION-NEXT: G_BR %bb.2
72 ; POSTSELECTION-LABEL: name: test
73 ; POSTSELECTION: bb.1.entry:
74 ; POSTSELECTION-NEXT: successors: %bb.3(0x40000000), %bb.2(0x40000000)
75 ; POSTSELECTION-NEXT: liveins: $w0, $w1
76 ; POSTSELECTION-NEXT: {{ $}}
77 ; POSTSELECTION-NEXT: [[COPY:%[0-9]+]]:gpr32 = COPY $w0
78 ; POSTSELECTION-NEXT: [[COPY1:%[0-9]+]]:gpr32 = COPY $w1
79 ; POSTSELECTION-NEXT: [[COPY2:%[0-9]+]]:gpr32 = COPY $wzr
80 ; POSTSELECTION-NEXT: [[MOVi32imm:%[0-9]+]]:gpr32 = MOVi32imm 100000
81 ; POSTSELECTION-NEXT: TBNZW [[COPY1]], 0, %bb.3
82 ; POSTSELECTION-NEXT: B %bb.2
83 ; POSTSELECTION-NEXT: {{ $}}
84 ; POSTSELECTION-NEXT: bb.2.common.ret:
85 ; POSTSELECTION-NEXT: [[PHI:%[0-9]+]]:gpr32 = PHI %7, %bb.3, [[COPY2]], %bb.1
86 ; POSTSELECTION-NEXT: $w0 = COPY [[PHI]]
87 ; POSTSELECTION-NEXT: RET_ReallyLR implicit $w0
88 ; POSTSELECTION-NEXT: {{ $}}
89 ; POSTSELECTION-NEXT: bb.3.cont:
90 ; POSTSELECTION-NEXT: successors: %bb.2(0x80000000)
91 ; POSTSELECTION-NEXT: {{ $}}
92 ; POSTSELECTION-NEXT: [[ADDWrr:%[0-9]+]]:gpr32 = ADDWrr [[COPY]], [[MOVi32imm]]
93 ; POSTSELECTION-NEXT: ADJCALLSTACKDOWN 0, 0, implicit-def $sp, implicit $sp
94 ; POSTSELECTION-NEXT: BL @callee, csr_darwin_aarch64_aapcs, implicit-def $lr, implicit $sp
95 ; POSTSELECTION-NEXT: ADJCALLSTACKUP 0, 0, implicit-def $sp, implicit $sp
96 ; POSTSELECTION-NEXT: B %bb.2
98 %hc = bitcast i32 100000 to i32
99 br i1 %c, label %cont, label %end
101 %add = add i32 %a, %hc