1 ; RUN: opt -S -passes=objc-arc-contract < %s | FileCheck %s
3 ; The optimizer should be able to move the autorelease past a control triangle
4 ; and various scary looking things and fold it into an objc_retainAutorelease.
7 ; CHECK: tail call ptr @llvm.objc.retainAutorelease(ptr %tmp71x) [[NUW:#[0-9]+]]
10 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
11 target triple = "x86_64-apple-darwin11.0.0"
13 %0 = type { ptr, ptr }
14 %1 = type { ptr, ptr }
15 %2 = type { ptr, ptr, ptr, ptr, ptr }
17 %4 = type { i32, i32, i32, ptr, ptr, ptr, ptr, ptr, ptr, ptr }
18 %5 = type { i32, i32, [0 x %6] }
19 %6 = type { ptr, ptr, ptr }
20 %7 = type { i64, [0 x ptr] }
21 %8 = type { ptr, ptr, ptr, ptr, ptr, ptr, ptr, ptr, i32, i32 }
22 %9 = type { i32, i32, [0 x %1] }
23 %10 = type { i32, i32, [0 x %11] }
24 %11 = type { ptr, ptr, ptr, i32, i32 }
25 %12 = type { ptr, i32, ptr, i64 }
40 @"\01l_objc_msgSend_fixup_alloc" = external hidden global %0, section "__DATA, __objc_msgrefs, coalesced", align 16
41 @"\01L_OBJC_SELECTOR_REFERENCES_8" = external hidden global ptr, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
42 @"\01L_OBJC_SELECTOR_REFERENCES_3725" = external hidden global ptr, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
43 @"\01L_OBJC_CLASSLIST_REFERENCES_$_40" = external hidden global ptr, section "__DATA, __objc_classrefs, regular, no_dead_strip", align 8
44 @"\01L_OBJC_SELECTOR_REFERENCES_4227" = external hidden global ptr, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
45 @"\01L_OBJC_SELECTOR_REFERENCES_4631" = external hidden global ptr, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
46 @"\01L_OBJC_CLASSLIST_REFERENCES_$_70" = external hidden global ptr, section "__DATA, __objc_classrefs, regular, no_dead_strip", align 8
47 @"\01L_OBJC_SELECTOR_REFERENCES_148" = external hidden global ptr, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
48 @"\01L_OBJC_SELECTOR_REFERENCES_159" = external hidden global ptr, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
49 @"\01L_OBJC_SELECTOR_REFERENCES_188" = external hidden global ptr, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
50 @"\01L_OBJC_SELECTOR_REFERENCES_328" = external hidden global ptr, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
51 @"\01l_objc_msgSend_fixup_objectAtIndex_" = external hidden global %0, section "__DATA, __objc_msgrefs, coalesced", align 16
52 @_unnamed_cfstring_386 = external hidden constant %12, section "__DATA,__cfstring"
53 @"\01l_objc_msgSend_fixup_count" = external hidden global %0, section "__DATA, __objc_msgrefs, coalesced", align 16
54 @"\01L_OBJC_SELECTOR_REFERENCES_389" = external hidden global ptr, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
55 @"\01L_OBJC_SELECTOR_REFERENCES_391" = external hidden global ptr, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
56 @"\01L_OBJC_SELECTOR_REFERENCES_393" = external hidden global ptr, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
57 @NSPrintHeaderAndFooter = external constant ptr
58 @"\01L_OBJC_SELECTOR_REFERENCES_395" = external hidden global ptr, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
59 @"\01L_OBJC_CLASSLIST_REFERENCES_$_396" = external hidden global ptr, section "__DATA, __objc_classrefs, regular, no_dead_strip", align 8
60 @"\01L_OBJC_SELECTOR_REFERENCES_398" = external hidden global ptr, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
61 @"\01L_OBJC_SELECTOR_REFERENCES_400" = external hidden global ptr, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
62 @"\01L_OBJC_SELECTOR_REFERENCES_402" = external hidden global ptr, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
63 @"\01L_OBJC_SELECTOR_REFERENCES_404" = external hidden global ptr, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
64 @"\01L_OBJC_SELECTOR_REFERENCES_406" = external hidden global ptr, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
65 @"\01L_OBJC_SELECTOR_REFERENCES_408" = external hidden global ptr, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
66 @"\01L_OBJC_CLASSLIST_REFERENCES_$_409" = external hidden global ptr, section "__DATA, __objc_classrefs, regular, no_dead_strip", align 8
67 @"\01L_OBJC_SELECTOR_REFERENCES_411" = external hidden global ptr, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
68 @"\01L_OBJC_SELECTOR_REFERENCES_413" = external hidden global ptr, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
69 @"\01L_OBJC_SELECTOR_REFERENCES_415" = external hidden global ptr, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
71 declare ptr @objc_msgSend(ptr, ptr, ...)
73 declare ptr @llvm.objc.retain(ptr)
75 declare void @llvm.objc.release(ptr)
77 declare ptr @llvm.objc.autorelease(ptr)
79 declare ptr @llvm.objc.explicit_autorelease(ptr)
81 define hidden ptr @foo(ptr %arg, ptr %arg2) {
83 %tmp = load ptr, ptr @"\01L_OBJC_SELECTOR_REFERENCES_3725", align 8
84 %tmp5 = tail call ptr @objc_msgSend(ptr %arg, ptr %tmp)
85 %tmp7 = tail call ptr @llvm.objc.retain(ptr %tmp5) nounwind
86 %tmp8 = load ptr, ptr @"\01L_OBJC_CLASSLIST_REFERENCES_$_40", align 8
87 %tmp9 = load ptr, ptr @"\01L_OBJC_SELECTOR_REFERENCES_4227", align 8
88 %tmp11 = tail call ptr @objc_msgSend(ptr %tmp8, ptr %tmp9)
89 %tmp12 = load ptr, ptr @"\01L_OBJC_SELECTOR_REFERENCES_4631", align 8
90 %tmp14 = tail call signext i8 @objc_msgSend(ptr %tmp11, ptr %tmp12, ptr @_unnamed_cfstring_386)
91 %tmp16 = load ptr, ptr @"\01l_objc_msgSend_fixup_count", align 16
92 %tmp18 = tail call i64 %tmp16(ptr %arg2, ptr @"\01l_objc_msgSend_fixup_count")
93 %tmp19 = icmp eq i64 %tmp18, 0
94 br i1 %tmp19, label %bb22, label %bb20
97 %tmp21 = icmp eq i8 %tmp14, 0
101 %tmp24 = icmp eq i8 %tmp14, 0
102 br i1 %tmp24, label %bb46, label %bb25
104 bb25: ; preds = %bb22, %bb20
105 %tmp26 = phi i1 [ %tmp21, %bb20 ], [ false, %bb22 ]
106 %tmp27 = load ptr, ptr @"\01L_OBJC_SELECTOR_REFERENCES_188", align 8
107 %tmp28 = tail call ptr @objc_msgSend(ptr %tmp7, ptr %tmp27)
108 %tmp29 = tail call ptr @llvm.objc.explicit_autorelease(ptr %tmp28) nounwind
109 tail call void @llvm.objc.release(ptr %tmp7) nounwind
110 %tmp31 = load ptr, ptr @"\01L_OBJC_SELECTOR_REFERENCES_389", align 8
111 %tmp32 = tail call ptr @objc_msgSend(ptr %tmp29, ptr %tmp31)
112 %tmp33 = load ptr, ptr @"\01L_OBJC_SELECTOR_REFERENCES_391", align 8
113 tail call void @objc_msgSend(ptr %tmp32, ptr %tmp33, ptr %arg2)
114 br i1 %tmp26, label %bb46, label %bb35
116 bb35: ; preds = %bb25
117 %tmp36 = load ptr, ptr @"\01L_OBJC_SELECTOR_REFERENCES_389", align 8
118 %tmp37 = tail call ptr @objc_msgSend(ptr %tmp29, ptr %tmp36)
119 %tmp38 = load ptr, ptr @"\01L_OBJC_CLASSLIST_REFERENCES_$_70", align 8
120 %tmp39 = load ptr, ptr @"\01L_OBJC_SELECTOR_REFERENCES_393", align 8
121 %tmp41 = tail call ptr @objc_msgSend(ptr %tmp38, ptr %tmp39, i8 signext 1)
122 %tmp43 = load ptr, ptr @NSPrintHeaderAndFooter, align 8
123 %tmp44 = load ptr, ptr @"\01L_OBJC_SELECTOR_REFERENCES_159", align 8
124 tail call void @objc_msgSend(ptr %tmp37, ptr %tmp44, ptr %tmp41, ptr %tmp43)
127 bb46: ; preds = %bb35, %bb25, %bb22
128 %tmp47 = phi ptr [ %tmp29, %bb35 ], [ %tmp29, %bb25 ], [ %tmp7, %bb22 ]
129 %tmp48 = load ptr, ptr @"\01L_OBJC_SELECTOR_REFERENCES_328", align 8
130 %tmp49 = tail call ptr @objc_msgSend(ptr %arg, ptr %tmp48)
131 %tmp51 = load ptr, ptr @"\01l_objc_msgSend_fixup_count", align 16
132 %tmp53 = tail call i64 %tmp51(ptr %tmp49, ptr @"\01l_objc_msgSend_fixup_count")
133 %tmp54 = icmp eq i64 %tmp53, 0
134 br i1 %tmp54, label %bb55, label %bb57
136 bb55: ; preds = %bb46
137 %tmp56 = load ptr, ptr @"\01L_OBJC_SELECTOR_REFERENCES_395", align 8
138 tail call void @objc_msgSend(ptr %arg, ptr %tmp56)
141 bb57: ; preds = %bb55, %bb46
142 %tmp58 = load ptr, ptr @"\01L_OBJC_CLASSLIST_REFERENCES_$_396", align 8
143 %tmp59 = load ptr, ptr @"\01L_OBJC_SELECTOR_REFERENCES_328", align 8
144 %tmp60 = tail call ptr @objc_msgSend(ptr %arg, ptr %tmp59)
145 %tmp62 = load ptr, ptr @"\01l_objc_msgSend_fixup_objectAtIndex_", align 16
146 %tmp64 = tail call ptr %tmp62(ptr %tmp60, ptr @"\01l_objc_msgSend_fixup_objectAtIndex_", i64 0)
147 %tmp65 = load ptr, ptr @"\01L_OBJC_SELECTOR_REFERENCES_398", align 8
148 %tmp66 = tail call ptr @objc_msgSend(ptr %tmp64, ptr %tmp65)
149 %tmp68 = load ptr, ptr @"\01L_OBJC_SELECTOR_REFERENCES_400", align 8
150 %tmp70 = tail call ptr @objc_msgSend(ptr %tmp58, ptr %tmp68, ptr %tmp66, ptr %tmp47)
151 ; hack to prevent the optimize from using objc_retainAutoreleasedReturnValue.
152 %tmp71x = getelementptr i8, ptr %tmp70, i64 1
153 %tmp72 = tail call ptr @llvm.objc.retain(ptr %tmp71x) nounwind
154 %tmp73 = load ptr, ptr @"\01L_OBJC_SELECTOR_REFERENCES_402", align 8
155 tail call void @objc_msgSend(ptr %tmp72, ptr %tmp73, i8 signext 1)
156 %tmp74 = load ptr, ptr @"\01L_OBJC_SELECTOR_REFERENCES_404", align 8
157 tail call void @objc_msgSend(ptr %tmp72, ptr %tmp74, i8 signext 1)
158 %tmp75 = load ptr, ptr @"\01L_OBJC_SELECTOR_REFERENCES_328", align 8
159 %tmp76 = tail call ptr @objc_msgSend(ptr %arg, ptr %tmp75)
160 %tmp78 = load ptr, ptr @"\01l_objc_msgSend_fixup_objectAtIndex_", align 16
161 %tmp80 = tail call ptr %tmp78(ptr %tmp76, ptr @"\01l_objc_msgSend_fixup_objectAtIndex_", i64 0)
162 %tmp81 = load ptr, ptr @"\01L_OBJC_SELECTOR_REFERENCES_406", align 8
163 tail call void @objc_msgSend(ptr %tmp80, ptr %tmp81, i64 9223372036854775807)
164 %tmp82 = load ptr, ptr @"\01L_OBJC_SELECTOR_REFERENCES_408", align 8
165 %tmp83 = tail call ptr @objc_msgSend(ptr %tmp72, ptr %tmp82)
166 %tmp85 = tail call ptr @llvm.objc.retain(ptr %tmp83) nounwind
167 %tmp86 = load ptr, ptr @"\01L_OBJC_CLASSLIST_REFERENCES_$_409", align 8
168 %tmp88 = load ptr, ptr @"\01l_objc_msgSend_fixup_alloc", align 16
169 %tmp90 = tail call ptr %tmp88(ptr %tmp86, ptr @"\01l_objc_msgSend_fixup_alloc")
170 %tmp91 = load ptr, ptr @"\01L_OBJC_SELECTOR_REFERENCES_8", align 8
171 %tmp92 = tail call ptr @objc_msgSend(ptr %tmp90, ptr %tmp91)
172 %tmp93 = tail call ptr @llvm.objc.explicit_autorelease(ptr %tmp92) nounwind
173 %tmp95 = load ptr, ptr @"\01L_OBJC_SELECTOR_REFERENCES_411", align 8
174 tail call void @objc_msgSend(ptr %tmp85, ptr %tmp95, ptr %tmp93)
175 tail call void @llvm.objc.release(ptr %tmp93) nounwind
176 %tmp96 = load ptr, ptr @"\01L_OBJC_SELECTOR_REFERENCES_148", align 8
177 %tmp97 = tail call signext i8 @objc_msgSend(ptr %arg, ptr %tmp96)
178 %tmp98 = icmp eq i8 %tmp97, 0
179 br i1 %tmp98, label %bb99, label %bb104
181 bb99: ; preds = %bb57
182 %tmp100 = load ptr, ptr @"\01L_OBJC_SELECTOR_REFERENCES_413", align 8
183 %tmp101 = tail call i64 @objc_msgSend(ptr %tmp85, ptr %tmp100)
184 %tmp102 = or i64 %tmp101, 12
185 %tmp103 = load ptr, ptr @"\01L_OBJC_SELECTOR_REFERENCES_415", align 8
186 tail call void @objc_msgSend(ptr %tmp85, ptr %tmp103, i64 %tmp102)
189 bb104: ; preds = %bb99, %bb57
190 %tmp105 = call ptr @llvm.objc.autorelease(ptr %tmp72) nounwind
191 tail call void @llvm.objc.release(ptr %tmp85) nounwind
192 tail call void @llvm.objc.release(ptr %tmp47) nounwind
196 ; CHECK: attributes [[NUW]] = { nounwind }