xref: /llvm-project/llvm/test/CodeGen/ARM/sjlj-prepare-critical-edge.ll (revision bed1c7f061aa12417aa081e334afdba45767b938)
1; RUN: llc < %s -O1 -mtriple thumbv7-apple-ios6 | FileCheck %s
2; Just make sure no one tries to make the assumption that the normal edge of an
3; invoke is never a critical edge.  Previously, this code would assert.
4
5%struct.__CFString = type opaque
6
7declare void @bar(ptr, ptr)
8
9define noalias ptr @foo(ptr nocapture %inRefURL) noreturn ssp personality ptr @__gxx_personality_sj0 {
10entry:
11  %call = tail call ptr @bar3()
12  %call2 = invoke ptr @bar2()
13          to label %for.cond unwind label %lpad
14
15for.cond:                                         ; preds = %entry, %for.cond
16  invoke void @bar(ptr undef, ptr null)
17          to label %for.cond unwind label %lpad5
18
19lpad:                                             ; preds = %entry
20  %0 = landingpad { ptr, i32 }
21          cleanup
22  %1 = extractvalue { ptr, i32 } %0, 0
23  %2 = extractvalue { ptr, i32 } %0, 1
24  br label %ehcleanup
25
26lpad5:                                            ; preds = %for.cond
27  %3 = landingpad { ptr, i32 }
28          cleanup
29  %4 = extractvalue { ptr, i32 } %3, 0
30  %5 = extractvalue { ptr, i32 } %3, 1
31  invoke void @release(ptr %call2)
32          to label %ehcleanup unwind label %terminate.lpad.i.i16
33
34terminate.lpad.i.i16:                             ; preds = %lpad5
35  %6 = landingpad { ptr, i32 }
36          catch ptr null
37  tail call void @terminatev() noreturn nounwind
38  unreachable
39
40ehcleanup:                                        ; preds = %lpad5, %lpad
41  %exn.slot.0 = phi ptr [ %1, %lpad ], [ %4, %lpad5 ]
42  %ehselector.slot.0 = phi i32 [ %2, %lpad ], [ %5, %lpad5 ]
43  invoke void @release(ptr %call)
44          to label %_ZN5SmartIPK10__CFStringED1Ev.exit unwind label %terminate.lpad.i.i
45
46terminate.lpad.i.i:                               ; preds = %ehcleanup
47  %7 = landingpad { ptr, i32 }
48          catch ptr null
49  tail call void @terminatev() noreturn nounwind
50  unreachable
51
52_ZN5SmartIPK10__CFStringED1Ev.exit:               ; preds = %ehcleanup
53  %lpad.val = insertvalue { ptr, i32 } undef, ptr %exn.slot.0, 0
54  %lpad.val12 = insertvalue { ptr, i32 } %lpad.val, i32 %ehselector.slot.0, 1
55  resume { ptr, i32 } %lpad.val12
56}
57
58declare ptr @bar3()
59
60declare ptr @bar2()
61
62declare i32 @__gxx_personality_sj0(...)
63
64declare void @release(ptr)
65
66declare void @terminatev()
67
68; Make sure that the instruction DemoteRegToStack inserts to reload
69; %call.i.i.i14.i.i follows the instruction that saves the value to the stack in
70; basic block %entry.do.body.i.i.i_crit_edge.
71; Previously, DemoteRegToStack would insert a load instruction into the entry
72; block to reload %call.i.i.i14.i.i before the phi instruction (%0) in block
73; %do.body.i.i.i.
74
75; CHECK-LABEL: __Z4foo1c:
76; CHECK: bl __Znwm
77; CHECK: {{.*}}@ %do.body.i.i.i.preheader
78; CHECK: str r0, [sp, [[OFFSET:#[0-9]+]]]
79; CHECK: {{.*}}@ %do.body.i.i.i
80; CHECK: ldr [[R0:r[0-9]+]], [sp, [[OFFSET]]]
81; CHECK: cbz [[R0]]
82
83%"class.std::__1::basic_string" = type { %"class.std::__1::__compressed_pair" }
84%"class.std::__1::__compressed_pair" = type { %"class.std::__1::__libcpp_compressed_pair_imp" }
85%"class.std::__1::__libcpp_compressed_pair_imp" = type { %"struct.std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__rep" }
86%"struct.std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__rep" = type { %union.anon }
87%union.anon = type { %"struct.std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__long" }
88%"struct.std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__long" = type { i32, i32, ptr }
89
90@.str = private unnamed_addr constant [12 x i8] c"some_string\00", align 1
91
92define void @_Z4foo1c(i8 signext %a) personality ptr @__gxx_personality_sj0 {
93entry:
94  %s1 = alloca %"class.std::__1::basic_string", align 4
95  call void @_ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEPKcm(ptr %s1, ptr @.str, i32 11)
96  %call.i.i.i14.i.i = invoke noalias ptr @_Znwm(i32 1024)
97          to label %do.body.i.i.i unwind label %lpad.body
98
99do.body.i.i.i:                                    ; preds = %entry, %_ZNSt3__116allocator_traitsINS_9allocatorIcEEE9constructIccEEvRS2_PT_RKT0_.exit.i.i.i
100  %lsr.iv = phi i32 [ %lsr.iv.next, %_ZNSt3__116allocator_traitsINS_9allocatorIcEEE9constructIccEEvRS2_PT_RKT0_.exit.i.i.i ], [ -1024, %entry ]
101  %0 = phi ptr [ %incdec.ptr.i.i.i, %_ZNSt3__116allocator_traitsINS_9allocatorIcEEE9constructIccEEvRS2_PT_RKT0_.exit.i.i.i ], [ %call.i.i.i14.i.i, %entry ]
102  %new.isnull.i.i.i.i = icmp eq ptr %0, null
103  br i1 %new.isnull.i.i.i.i, label %_ZNSt3__116allocator_traitsINS_9allocatorIcEEE9constructIccEEvRS2_PT_RKT0_.exit.i.i.i, label %new.notnull.i.i.i.i
104
105new.notnull.i.i.i.i:                              ; preds = %do.body.i.i.i
106  store i8 %a, ptr %0, align 1
107  br label %_ZNSt3__116allocator_traitsINS_9allocatorIcEEE9constructIccEEvRS2_PT_RKT0_.exit.i.i.i
108
109_ZNSt3__116allocator_traitsINS_9allocatorIcEEE9constructIccEEvRS2_PT_RKT0_.exit.i.i.i: ; preds = %new.notnull.i.i.i.i, %do.body.i.i.i
110  %1 = phi ptr [ null, %do.body.i.i.i ], [ %0, %new.notnull.i.i.i.i ]
111  %incdec.ptr.i.i.i = getelementptr inbounds i8, ptr %1, i32 1
112  %lsr.iv.next = add i32 %lsr.iv, 1
113  %cmp.i16.i.i = icmp eq i32 %lsr.iv.next, 0
114  br i1 %cmp.i16.i.i, label %invoke.cont, label %do.body.i.i.i
115
116invoke.cont:                                      ; preds = %_ZNSt3__116allocator_traitsINS_9allocatorIcEEE9constructIccEEvRS2_PT_RKT0_.exit.i.i.i
117  invoke void @_Z4foo2Pci(ptr %call.i.i.i14.i.i, i32 1024)
118          to label %invoke.cont5 unwind label %lpad2
119
120invoke.cont5:                                     ; preds = %invoke.cont
121  %cmp.i.i.i15 = icmp eq ptr %call.i.i.i14.i.i, null
122  br i1 %cmp.i.i.i15, label %invoke.cont6, label %_ZNSt3__113__vector_baseIcNS_9allocatorIcEEE5clearEv.exit.i.i.i19
123
124_ZNSt3__113__vector_baseIcNS_9allocatorIcEEE5clearEv.exit.i.i.i19: ; preds = %invoke.cont5
125  call void @_ZdlPv(ptr %call.i.i.i14.i.i)
126  br label %invoke.cont6
127
128invoke.cont6:                                     ; preds = %_ZNSt3__113__vector_baseIcNS_9allocatorIcEEE5clearEv.exit.i.i.i19, %invoke.cont5
129  %call10 = call ptr @_ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED1Ev(ptr %s1)
130  ret void
131
132lpad.body:                                        ; preds = %entry
133  %2 = landingpad { ptr, i32 }
134          cleanup
135  %3 = extractvalue { ptr, i32 } %2, 0
136  %4 = extractvalue { ptr, i32 } %2, 1
137  br label %ehcleanup
138
139lpad2:                                            ; preds = %invoke.cont
140  %5 = landingpad { ptr, i32 }
141          cleanup
142  %6 = extractvalue { ptr, i32 } %5, 0
143  %7 = extractvalue { ptr, i32 } %5, 1
144  %cmp.i.i.i21 = icmp eq ptr %call.i.i.i14.i.i, null
145  br i1 %cmp.i.i.i21, label %ehcleanup, label %_ZNSt3__113__vector_baseIcNS_9allocatorIcEEE5clearEv.exit.i.i.i26
146
147_ZNSt3__113__vector_baseIcNS_9allocatorIcEEE5clearEv.exit.i.i.i26: ; preds = %lpad2
148  call void @_ZdlPv(ptr %call.i.i.i14.i.i)
149  br label %ehcleanup
150
151ehcleanup:                                        ; preds = %_ZNSt3__113__vector_baseIcNS_9allocatorIcEEE5clearEv.exit.i.i.i26, %lpad2, %lpad.body
152  %exn.slot.0 = phi ptr [ %3, %lpad.body ], [ %6, %lpad2 ], [ %6, %_ZNSt3__113__vector_baseIcNS_9allocatorIcEEE5clearEv.exit.i.i.i26 ]
153  %ehselector.slot.0 = phi i32 [ %4, %lpad.body ], [ %7, %lpad2 ], [ %7, %_ZNSt3__113__vector_baseIcNS_9allocatorIcEEE5clearEv.exit.i.i.i26 ]
154  %call12 = invoke ptr @_ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED1Ev(ptr %s1)
155          to label %eh.resume unwind label %terminate.lpad
156
157eh.resume:                                        ; preds = %ehcleanup
158  %lpad.val = insertvalue { ptr, i32 } undef, ptr %exn.slot.0, 0
159  %lpad.val13 = insertvalue { ptr, i32 } %lpad.val, i32 %ehselector.slot.0, 1
160  resume { ptr, i32 } %lpad.val13
161
162terminate.lpad:                                   ; preds = %ehcleanup
163  %8 = landingpad { ptr, i32 }
164          catch ptr null
165  %9 = extractvalue { ptr, i32 } %8, 0
166  call void @__clang_call_terminate(ptr %9)
167  unreachable
168}
169
170declare void @_Z4foo2Pci(ptr, i32)
171
172define linkonce_odr hidden void @__clang_call_terminate(ptr) {
173  %2 = tail call ptr @__cxa_begin_catch(ptr %0)
174  tail call void @_ZSt9terminatev()
175  unreachable
176}
177
178declare ptr @__cxa_begin_catch(ptr)
179declare void @_ZSt9terminatev()
180declare ptr @_ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEED1Ev(ptr returned)
181declare void @_ZdlPv(ptr) #3
182declare noalias ptr @_Znwm(i32)
183declare void @_ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE6__initEPKcm(ptr, ptr, i32)
184declare void @_Unwind_SjLj_Register(ptr)
185declare void @_Unwind_SjLj_Unregister(ptr)
186declare ptr @llvm.frameaddress(i32)
187declare ptr @llvm.stacksave()
188declare void @llvm.stackrestore(ptr)
189declare i32 @llvm.eh.sjlj.setjmp(ptr)
190declare ptr @llvm.eh.sjlj.lsda()
191declare void @llvm.eh.sjlj.callsite(i32)
192declare void @llvm.eh.sjlj.functioncontext(ptr)
193