1 ; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2 ; RUN: llc -O0 -mtriple=aarch64-apple-ios -global-isel -stop-after=legalizer %s -o - | FileCheck %s
4 @global_var = external global i32
5 declare i32 @__gxx_personality_v0(...)
6 declare void @may_throw()
8 ; This test checks that the widened G_CONSTANT operand to the phi in "continue" bb
9 ; is placed before the potentially throwing call in the entry block.
10 define i1 @test_lpad_phi_widen_into_pred() personality ptr @__gxx_personality_v0 {
11 ; CHECK-LABEL: name: test_lpad_phi_widen_into_pred
12 ; CHECK: bb.1 (%ir-block.0):
13 ; CHECK-NEXT: successors: %bb.3(0x40000000), %bb.2(0x40000000)
15 ; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 11
16 ; CHECK-NEXT: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @global_var
17 ; CHECK-NEXT: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 42
18 ; CHECK-NEXT: G_STORE [[C1]](s32), [[GV]](p0) :: (store (s32) into @global_var)
19 ; CHECK-NEXT: [[C2:%[0-9]+]]:_(s16) = G_CONSTANT i16 1
20 ; CHECK-NEXT: G_INVOKE_REGION_START
21 ; CHECK-NEXT: EH_LABEL <mcsymbol >
22 ; CHECK-NEXT: ADJCALLSTACKDOWN 0, 0, implicit-def $sp, implicit $sp
23 ; CHECK-NEXT: BL @may_throw, csr_darwin_aarch64_aapcs, implicit-def $lr, implicit $sp
24 ; CHECK-NEXT: ADJCALLSTACKUP 0, 0, implicit-def $sp, implicit $sp
25 ; CHECK-NEXT: EH_LABEL <mcsymbol >
26 ; CHECK-NEXT: G_BR %bb.3
28 ; CHECK-NEXT: bb.2.lpad (landing-pad):
29 ; CHECK-NEXT: successors: %bb.3(0x80000000)
30 ; CHECK-NEXT: liveins: $x0, $x1
32 ; CHECK-NEXT: [[PHI:%[0-9]+]]:_(s32) = G_PHI [[C]](s32), %bb.1
33 ; CHECK-NEXT: EH_LABEL <mcsymbol >
34 ; CHECK-NEXT: [[GV1:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @global_var
35 ; CHECK-NEXT: G_STORE [[PHI]](s32), [[GV1]](p0) :: (store (s32) into @global_var)
36 ; CHECK-NEXT: [[C3:%[0-9]+]]:_(s16) = G_CONSTANT i16 0
37 ; CHECK-NEXT: G_BR %bb.3
39 ; CHECK-NEXT: bb.3.continue:
40 ; CHECK-NEXT: [[PHI1:%[0-9]+]]:_(s16) = G_PHI [[C2]](s16), %bb.1, [[C3]](s16), %bb.2
41 ; CHECK-NEXT: [[C4:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
42 ; CHECK-NEXT: [[ANYEXT:%[0-9]+]]:_(s32) = G_ANYEXT [[PHI1]](s16)
43 ; CHECK-NEXT: [[AND:%[0-9]+]]:_(s32) = G_AND [[ANYEXT]], [[C4]]
44 ; CHECK-NEXT: $w0 = COPY [[AND]](s32)
45 ; CHECK-NEXT: RET_ReallyLR implicit $w0
46 store i32 42, ptr @global_var
47 invoke void @may_throw()
48 to label %continue unwind label %lpad
50 lpad: ; preds = %entry
51 %p = phi i32 [ 11, %0 ]
52 %1 = landingpad { ptr, i32 }
54 store i32 %p, ptr @global_var
57 continue: ; preds = %entry, %lpad
58 %r.0 = phi i1 [ 1, %0 ], [ 0, %lpad ]
62 ; Same test but with extensions.
63 define i1 @test_lpad_phi_widen_into_pred_ext(ptr %ptr) personality ptr @__gxx_personality_v0 {
64 ; CHECK-LABEL: name: test_lpad_phi_widen_into_pred_ext
65 ; CHECK: bb.1 (%ir-block.0):
66 ; CHECK-NEXT: successors: %bb.3(0x40000000), %bb.2(0x40000000)
67 ; CHECK-NEXT: liveins: $x0
69 ; CHECK-NEXT: [[COPY:%[0-9]+]]:_(p0) = COPY $x0
70 ; CHECK-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 11
71 ; CHECK-NEXT: [[GV:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @global_var
72 ; CHECK-NEXT: [[C1:%[0-9]+]]:_(s32) = G_CONSTANT i32 42
73 ; CHECK-NEXT: G_STORE [[C1]](s32), [[GV]](p0) :: (store (s32) into @global_var)
74 ; CHECK-NEXT: [[LOAD:%[0-9]+]]:_(s8) = G_LOAD [[COPY]](p0) :: (load (s8) from %ir.ptr)
75 ; CHECK-NEXT: [[ASSERT_ZEXT:%[0-9]+]]:_(s8) = G_ASSERT_ZEXT [[LOAD]], 1
76 ; CHECK-NEXT: [[ANYEXT:%[0-9]+]]:_(s16) = G_ANYEXT [[ASSERT_ZEXT]](s8)
77 ; CHECK-NEXT: G_INVOKE_REGION_START
78 ; CHECK-NEXT: EH_LABEL <mcsymbol >
79 ; CHECK-NEXT: ADJCALLSTACKDOWN 0, 0, implicit-def $sp, implicit $sp
80 ; CHECK-NEXT: BL @may_throw, csr_darwin_aarch64_aapcs, implicit-def $lr, implicit $sp
81 ; CHECK-NEXT: ADJCALLSTACKUP 0, 0, implicit-def $sp, implicit $sp
82 ; CHECK-NEXT: EH_LABEL <mcsymbol >
83 ; CHECK-NEXT: G_BR %bb.3
85 ; CHECK-NEXT: bb.2.lpad (landing-pad):
86 ; CHECK-NEXT: successors: %bb.3(0x80000000)
87 ; CHECK-NEXT: liveins: $x0, $x1
89 ; CHECK-NEXT: [[PHI:%[0-9]+]]:_(s32) = G_PHI [[C]](s32), %bb.1
90 ; CHECK-NEXT: EH_LABEL <mcsymbol >
91 ; CHECK-NEXT: [[GV1:%[0-9]+]]:_(p0) = G_GLOBAL_VALUE @global_var
92 ; CHECK-NEXT: G_STORE [[PHI]](s32), [[GV1]](p0) :: (store (s32) into @global_var)
93 ; CHECK-NEXT: [[C2:%[0-9]+]]:_(s16) = G_CONSTANT i16 0
94 ; CHECK-NEXT: G_BR %bb.3
96 ; CHECK-NEXT: bb.3.continue:
97 ; CHECK-NEXT: [[PHI1:%[0-9]+]]:_(s16) = G_PHI [[ANYEXT]](s16), %bb.1, [[C2]](s16), %bb.2
98 ; CHECK-NEXT: [[C3:%[0-9]+]]:_(s32) = G_CONSTANT i32 1
99 ; CHECK-NEXT: [[ANYEXT1:%[0-9]+]]:_(s32) = G_ANYEXT [[PHI1]](s16)
100 ; CHECK-NEXT: [[AND:%[0-9]+]]:_(s32) = G_AND [[ANYEXT1]], [[C3]]
101 ; CHECK-NEXT: $w0 = COPY [[AND]](s32)
102 ; CHECK-NEXT: RET_ReallyLR implicit $w0
103 store i32 42, ptr @global_var
104 %v = load i1, ptr %ptr
105 invoke void @may_throw()
106 to label %continue unwind label %lpad
108 lpad: ; preds = %entry
109 %p = phi i32 [ 11, %0 ]
110 %1 = landingpad { ptr, i32 }
112 store i32 %p, ptr @global_var
115 continue: ; preds = %entry, %lpad
116 %r.0 = phi i1 [ %v, %0 ], [ 0, %lpad ]