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