blob: 72f05ffaac9d6ddfc1bd2f9ede0a07c76a63dc17 [file] [log] [blame]
John McCalld935e9c2011-06-15 23:37:01 +00001; RUN: opt -objc-arc -S < %s | FileCheck %s
2
3target datalayout = "e-p:64:64:64"
4
5declare i8* @objc_retain(i8*)
6declare void @objc_release(i8*)
7declare i8* @objc_autorelease(i8*)
8declare void @objc_autoreleasePoolPop(i8*)
9declare void @objc_autoreleasePoolPush()
10declare i8* @objc_retainBlock(i8*)
11
12declare i8* @objc_retainedObject(i8*)
13declare i8* @objc_unretainedObject(i8*)
14declare i8* @objc_unretainedPointer(i8*)
15
16declare void @use_pointer(i8*)
17declare void @callee()
18declare void @callee_fnptr(void ()*)
19declare void @invokee()
20declare i8* @returner()
21
22declare void @llvm.dbg.value(metadata, i64, metadata)
23
24declare i8* @objc_msgSend(i8*, i8*, ...)
25
26; Simple retain+release pair deletion, with some intervening control
27; flow and harmless instructions.
28
29; CHECK: define void @test0(
30; CHECK-NOT: @objc_
31; CHECK: }
32define void @test0(i32* %x, i1 %p) nounwind {
33entry:
34 %a = bitcast i32* %x to i8*
35 %0 = call i8* @objc_retain(i8* %a) nounwind
36 br i1 %p, label %t, label %f
37
38t:
39 store i8 3, i8* %a
40 %b = bitcast i32* %x to float*
41 store float 2.0, float* %b
42 br label %return
43
44f:
45 store i32 7, i32* %x
46 br label %return
47
48return:
49 %c = bitcast i32* %x to i8*
50 call void @objc_release(i8* %c) nounwind
51 ret void
52}
53
54; Like test0 but the release isn't always executed when the retain is,
55; so the optimization is not safe.
56
57; TODO: Make the objc_release's argument be %0.
58
59; CHECK: define void @test1(
60; CHECK: @objc_retain(i8* %a)
61; CHECK: @objc_release
62; CHECK: }
63define void @test1(i32* %x, i1 %p, i1 %q) nounwind {
64entry:
65 %a = bitcast i32* %x to i8*
66 %0 = call i8* @objc_retain(i8* %a) nounwind
67 br i1 %p, label %t, label %f
68
69t:
70 store i8 3, i8* %a
71 %b = bitcast i32* %x to float*
72 store float 2.0, float* %b
73 br label %return
74
75f:
76 store i32 7, i32* %x
77 call void @callee()
78 br i1 %q, label %return, label %alt_return
79
80return:
81 %c = bitcast i32* %x to i8*
82 call void @objc_release(i8* %c) nounwind
83 ret void
84
85alt_return:
86 ret void
87}
88
89; Like test0 but the pointer is passed to an intervening call,
90; so the optimization is not safe.
91
92; CHECK: define void @test2(
93; CHECK: @objc_retain(i8* %a)
94; CHECK: @objc_release
95; CHECK: }
96define void @test2(i32* %x, i1 %p) nounwind {
97entry:
98 %a = bitcast i32* %x to i8*
99 %0 = call i8* @objc_retain(i8* %a) nounwind
100 br i1 %p, label %t, label %f
101
102t:
103 store i8 3, i8* %a
104 %b = bitcast i32* %x to float*
105 store float 2.0, float* %b
106 br label %return
107
108f:
109 store i32 7, i32* %x
110 call void @use_pointer(i8* %0)
111 %d = bitcast i32* %x to float*
112 store float 3.0, float* %d
113 br label %return
114
115return:
116 %c = bitcast i32* %x to i8*
117 call void @objc_release(i8* %c) nounwind
118 ret void
119}
120
121; Like test0 but the release is in a loop,
122; so the optimization is not safe.
123
124; TODO: For now, assume this can't happen.
125
126; CHECK: define void @test3(
127; TODO: @objc_retain(i8* %a)
128; TODO: @objc_release
129; CHECK: }
130define void @test3(i32* %x, i1* %q) nounwind {
131entry:
132 %a = bitcast i32* %x to i8*
133 %0 = call i8* @objc_retain(i8* %a) nounwind
134 br label %loop
135
136loop:
137 %c = bitcast i32* %x to i8*
138 call void @objc_release(i8* %c) nounwind
139 %j = volatile load i1* %q
140 br i1 %j, label %loop, label %return
141
142return:
143 ret void
144}
145
146; TODO: For now, assume this can't happen.
147
148; Like test0 but the retain is in a loop,
149; so the optimization is not safe.
150
151; CHECK: define void @test4(
152; TODO: @objc_retain(i8* %a)
153; TODO: @objc_release
154; CHECK: }
155define void @test4(i32* %x, i1* %q) nounwind {
156entry:
157 br label %loop
158
159loop:
160 %a = bitcast i32* %x to i8*
161 %0 = call i8* @objc_retain(i8* %a) nounwind
162 %j = volatile load i1* %q
163 br i1 %j, label %loop, label %return
164
165return:
166 %c = bitcast i32* %x to i8*
167 call void @objc_release(i8* %c) nounwind
168 ret void
169}
170
171; Like test0 but the pointer is conditionally passed to an intervening call,
172; so the optimization is not safe.
173
174; CHECK: define void @test5(
175; CHECK: @objc_retain(i8*
176; CHECK: @objc_release
177; CHECK: }
178define void @test5(i32* %x, i1 %q, i8* %y) nounwind {
179entry:
180 %a = bitcast i32* %x to i8*
181 %0 = call i8* @objc_retain(i8* %a) nounwind
182 %s = select i1 %q, i8* %y, i8* %0
183 call void @use_pointer(i8* %s)
184 store i32 7, i32* %x
185 %c = bitcast i32* %x to i8*
186 call void @objc_release(i8* %c) nounwind
187 ret void
188}
189
190; retain+release pair deletion, where the release happens on two different
191; flow paths.
192
193; CHECK: define void @test6(
194; CHECK-NOT: @objc_
195; CHECK: }
196define void @test6(i32* %x, i1 %p) nounwind {
197entry:
198 %a = bitcast i32* %x to i8*
199 %0 = call i8* @objc_retain(i8* %a) nounwind
200 br i1 %p, label %t, label %f
201
202t:
203 store i8 3, i8* %a
204 %b = bitcast i32* %x to float*
205 store float 2.0, float* %b
206 %ct = bitcast i32* %x to i8*
207 call void @objc_release(i8* %ct) nounwind
208 br label %return
209
210f:
211 store i32 7, i32* %x
212 call void @callee()
213 %cf = bitcast i32* %x to i8*
214 call void @objc_release(i8* %cf) nounwind
215 br label %return
216
217return:
218 ret void
219}
220
221; retain+release pair deletion, where the retain happens on two different
222; flow paths.
223
224; CHECK: define void @test7(
225; CHECK-NOT: @objc_
226; CHECK: }
227define void @test7(i32* %x, i1 %p) nounwind {
228entry:
229 %a = bitcast i32* %x to i8*
230 br i1 %p, label %t, label %f
231
232t:
233 %0 = call i8* @objc_retain(i8* %a) nounwind
234 store i8 3, i8* %a
235 %b = bitcast i32* %x to float*
236 store float 2.0, float* %b
237 br label %return
238
239f:
240 %1 = call i8* @objc_retain(i8* %a) nounwind
241 store i32 7, i32* %x
242 call void @callee()
243 br label %return
244
245return:
246 %c = bitcast i32* %x to i8*
247 call void @objc_release(i8* %c) nounwind
248 ret void
249}
250
251; Like test7, but there's a retain/retainBlock mismatch. Don't delete!
252
253; CHECK: define void @test7b
254; CHECK: t:
255; CHECK: call i8* @objc_retainBlock
256; CHECK: f:
257; CHECK: call i8* @objc_retain
258; CHECK: return:
259; CHECK: call void @objc_release
260; CHECK: }
261define void @test7b(i32* %x, i1 %p) nounwind {
262entry:
263 %a = bitcast i32* %x to i8*
264 br i1 %p, label %t, label %f
265
266t:
267 %0 = call i8* @objc_retainBlock(i8* %a) nounwind
268 store i8 3, i8* %a
269 %b = bitcast i32* %x to float*
270 store float 2.0, float* %b
271 br label %return
272
273f:
274 %1 = call i8* @objc_retain(i8* %a) nounwind
275 store i32 7, i32* %x
276 call void @callee()
277 br label %return
278
279return:
280 %c = bitcast i32* %x to i8*
281 call void @objc_release(i8* %c) nounwind
282 ret void
283}
284
285; retain+release pair deletion, where the retain and release both happen on
286; different flow paths. Wild!
287
288; CHECK: define void @test8(
289; CHECK-NOT: @objc_
290; CHECK: }
291define void @test8(i32* %x, i1 %p, i1 %q) nounwind {
292entry:
293 %a = bitcast i32* %x to i8*
294 br i1 %p, label %t, label %f
295
296t:
297 %0 = call i8* @objc_retain(i8* %a) nounwind
298 store i8 3, i8* %a
299 %b = bitcast i32* %x to float*
300 store float 2.0, float* %b
301 br label %mid
302
303f:
304 %1 = call i8* @objc_retain(i8* %a) nounwind
305 store i32 7, i32* %x
306 br label %mid
307
308mid:
309 br i1 %q, label %u, label %g
310
311u:
312 call void @callee()
313 %cu = bitcast i32* %x to i8*
314 call void @objc_release(i8* %cu) nounwind
315 br label %return
316
317g:
318 %cg = bitcast i32* %x to i8*
319 call void @objc_release(i8* %cg) nounwind
320 br label %return
321
322return:
323 ret void
324}
325
326; Trivial retain+release pair deletion.
327
328; CHECK: define void @test9(
329; CHECK-NOT: @objc_
330; CHECK: }
331define void @test9(i8* %x) nounwind {
332entry:
333 %0 = call i8* @objc_retain(i8* %x) nounwind
334 call void @objc_release(i8* %0) nounwind
335 ret void
336}
337
338; Retain+release pair, but on an unknown pointer relationship. Don't delete!
339
340; CHECK: define void @test9b
341; CHECK: @objc_retain(i8* %x)
342; CHECK: @objc_release(i8* %s)
343; CHECK: }
344define void @test9b(i8* %x, i1 %j, i8* %p) nounwind {
345entry:
346 %0 = call i8* @objc_retain(i8* %x) nounwind
347 %s = select i1 %j, i8* %x, i8* %p
348 call void @objc_release(i8* %s) nounwind
349 ret void
350}
351
352; Trivial retain+release pair with intervening calls - don't delete!
353
354; CHECK: define void @test10(
355; CHECK: @objc_retain(i8* %x)
Dan Gohmanbce94fd2011-08-22 17:27:02 +0000356; CHECK: @callee
John McCalld935e9c2011-06-15 23:37:01 +0000357; CHECK: @use_pointer
358; CHECK: @objc_release
359; CHECK: }
360define void @test10(i8* %x) nounwind {
361entry:
362 %0 = call i8* @objc_retain(i8* %x) nounwind
Dan Gohmanbce94fd2011-08-22 17:27:02 +0000363 call void @callee()
John McCalld935e9c2011-06-15 23:37:01 +0000364 call void @use_pointer(i8* %x)
365 call void @objc_release(i8* %0) nounwind
366 ret void
367}
368
369; Trivial retain+autoreleaserelease pair. Don't delete!
370; Also, add a tail keyword, since objc_retain can never be passed
371; a stack argument.
372
373; CHECK: define void @test11(
374; CHECK: tail call i8* @objc_retain(i8* %x) nounwind
375; CHECK: tail call i8* @objc_autorelease(i8* %0) nounwind
376; CHECK: }
377define void @test11(i8* %x) nounwind {
378entry:
379 %0 = call i8* @objc_retain(i8* %x) nounwind
380 call i8* @objc_autorelease(i8* %0) nounwind
381 call void @use_pointer(i8* %x)
382 ret void
383}
384
385; Same as test11 but with no use_pointer call. Delete the pair!
386
387; CHECK: define void @test11a(
388; CHECK: entry:
389; CHECK-NEXT: ret void
390; CHECK: }
391define void @test11a(i8* %x) nounwind {
392entry:
393 %0 = call i8* @objc_retain(i8* %x) nounwind
394 call i8* @objc_autorelease(i8* %0) nounwind
395 ret void
396}
397
398; Same as test11 but the value is returned. Do an RV optimization.
399
400; CHECK: define i8* @test11b(
401; CHECK: tail call i8* @objc_retain(i8* %x) nounwind
402; CHECK: tail call i8* @objc_autoreleaseReturnValue(i8* %0) nounwind
403; CHECK: }
404define i8* @test11b(i8* %x) nounwind {
405entry:
406 %0 = call i8* @objc_retain(i8* %x) nounwind
407 call i8* @objc_autorelease(i8* %0) nounwind
408 ret i8* %x
409}
410
411; Trivial retain,release pair with intervening call, but it's dominated
412; by another retain - delete!
413
414; CHECK: define void @test12(
415; CHECK-NEXT: entry:
416; CHECK-NEXT: @objc_retain(i8* %x)
417; CHECK-NOT: @objc_
418; CHECK: }
419define void @test12(i8* %x, i64 %n) {
420entry:
421 call i8* @objc_retain(i8* %x) nounwind
422 call i8* @objc_retain(i8* %x) nounwind
423 call void @use_pointer(i8* %x)
424 call void @use_pointer(i8* %x)
425 call void @objc_release(i8* %x) nounwind
426 ret void
427}
428
429; Trivial retain,autorelease pair. Don't delete!
430
431; CHECK: define void @test13(
432; CHECK: tail call i8* @objc_retain(i8* %x) nounwind
433; CHECK: tail call i8* @objc_retain(i8* %x) nounwind
434; CHECK: @use_pointer(i8* %x)
435; CHECK: tail call i8* @objc_autorelease(i8* %x) nounwind
436; CHECK: }
437define void @test13(i8* %x, i64 %n) {
438entry:
439 call i8* @objc_retain(i8* %x) nounwind
440 call i8* @objc_retain(i8* %x) nounwind
441 call void @use_pointer(i8* %x)
442 call i8* @objc_autorelease(i8* %x) nounwind
443 ret void
444}
445
446; Delete the retain+release pair.
447
448; CHECK: define void @test13b
449; CHECK-NEXT: entry:
450; CHECK-NEXT: @objc_retain(i8* %x)
451; CHECK-NEXT: @use_pointer
452; CHECK-NEXT: @use_pointer
453; CHECK-NEXT: ret void
454define void @test13b(i8* %x, i64 %n) {
455entry:
456 call i8* @objc_retain(i8* %x) nounwind
457 call i8* @objc_retain(i8* %x) nounwind
458 call void @use_pointer(i8* %x)
459 call void @use_pointer(i8* %x)
460 call void @objc_release(i8* %x) nounwind
461 ret void
462}
463
464; Don't delete the retain+release pair because there's an
465; autoreleasePoolPop in the way.
466
467; CHECK: define void @test13c
468; CHECK: @objc_retain(i8* %x)
469; CHECK: @objc_autoreleasePoolPop
470; CHECK: @objc_retain(i8* %x)
471; CHECK: @use_pointer
472; CHECK: @objc_release
473; CHECK: }
474define void @test13c(i8* %x, i64 %n) {
475entry:
476 call i8* @objc_retain(i8* %x) nounwind
477 call void @objc_autoreleasePoolPop(i8* undef)
478 call i8* @objc_retain(i8* %x) nounwind
479 call void @use_pointer(i8* %x)
480 call void @use_pointer(i8* %x)
481 call void @objc_release(i8* %x) nounwind
482 ret void
483}
484
485; Like test13c, but there's an autoreleasePoolPush in the way, but that
486; doesn't matter.
487
488; CHECK: define void @test13d
489; CHECK-NEXT: entry:
490; CHECK-NEXT: @objc_retain(i8* %x)
491; CHECK-NEXT: @objc_autoreleasePoolPush
492; CHECK-NEXT: @use_pointer
493; CHECK-NEXT: @use_pointer
494; CHECK-NEXT: ret void
495define void @test13d(i8* %x, i64 %n) {
496entry:
497 call i8* @objc_retain(i8* %x) nounwind
498 call void @objc_autoreleasePoolPush()
499 call i8* @objc_retain(i8* %x) nounwind
500 call void @use_pointer(i8* %x)
501 call void @use_pointer(i8* %x)
502 call void @objc_release(i8* %x) nounwind
503 ret void
504}
505
506; Trivial retain,release pair with intervening call, but it's post-dominated
507; by another release - delete!
508
509; CHECK: define void @test14(
510; CHECK-NEXT: entry:
511; CHECK-NEXT: @use_pointer
512; CHECK-NEXT: @use_pointer
513; CHECK-NEXT: @objc_release
514; CHECK-NEXT: ret void
515; CHECK-NEXT: }
516define void @test14(i8* %x, i64 %n) {
517entry:
518 call i8* @objc_retain(i8* %x) nounwind
519 call void @use_pointer(i8* %x)
520 call void @use_pointer(i8* %x)
521 call void @objc_release(i8* %x) nounwind
522 call void @objc_release(i8* %x) nounwind
523 ret void
524}
525
526; Trivial retain,autorelease pair with intervening call, but it's post-dominated
527; by another release. Don't delete anything.
528
529; CHECK: define void @test15(
530; CHECK-NEXT: entry:
531; CHECK-NEXT: @objc_retain(i8* %x)
532; CHECK-NEXT: @use_pointer
533; CHECK-NEXT: @objc_autorelease(i8* %x)
534; CHECK-NEXT: @objc_release
535; CHECK-NEXT: ret void
536; CHECK-NEXT: }
537define void @test15(i8* %x, i64 %n) {
538entry:
539 call i8* @objc_retain(i8* %x) nounwind
540 call void @use_pointer(i8* %x)
541 call i8* @objc_autorelease(i8* %x) nounwind
542 call void @objc_release(i8* %x) nounwind
543 ret void
544}
545
546; Trivial retain,autorelease pair, post-dominated
547; by another release. Delete the retain and release.
548
549; CHECK: define void @test15b
550; CHECK-NEXT: entry:
551; CHECK-NEXT: @objc_autorelease
552; CHECK-NEXT: ret void
553; CHECK-NEXT: }
554define void @test15b(i8* %x, i64 %n) {
555entry:
556 call i8* @objc_retain(i8* %x) nounwind
557 call i8* @objc_autorelease(i8* %x) nounwind
558 call void @objc_release(i8* %x) nounwind
559 ret void
560}
561
562; Retain+release pairs in diamonds, all dominated by a retain.
563
564; CHECK: define void @test16(
565; CHECK: @objc_retain(i8* %x)
566; CHECK-NOT: @objc
567; CHECK: }
568define void @test16(i1 %a, i1 %b, i8* %x) {
569entry:
570 call i8* @objc_retain(i8* %x) nounwind
571 br i1 %a, label %red, label %orange
572
573red:
574 call i8* @objc_retain(i8* %x) nounwind
575 br label %yellow
576
577orange:
578 call i8* @objc_retain(i8* %x) nounwind
579 br label %yellow
580
581yellow:
582 call void @use_pointer(i8* %x)
583 call void @use_pointer(i8* %x)
584 br i1 %b, label %green, label %blue
585
586green:
587 call void @objc_release(i8* %x) nounwind
588 br label %purple
589
590blue:
591 call void @objc_release(i8* %x) nounwind
592 br label %purple
593
594purple:
595 ret void
596}
597
598; Retain+release pairs in diamonds, all post-dominated by a release.
599
600; CHECK: define void @test17(
601; CHECK-NOT: @objc_
602; CHECK: purple:
603; CHECK: @objc_release
604; CHECK: }
605define void @test17(i1 %a, i1 %b, i8* %x) {
606entry:
607 br i1 %a, label %red, label %orange
608
609red:
610 call i8* @objc_retain(i8* %x) nounwind
611 br label %yellow
612
613orange:
614 call i8* @objc_retain(i8* %x) nounwind
615 br label %yellow
616
617yellow:
618 call void @use_pointer(i8* %x)
619 call void @use_pointer(i8* %x)
620 br i1 %b, label %green, label %blue
621
622green:
623 call void @objc_release(i8* %x) nounwind
624 br label %purple
625
626blue:
627 call void @objc_release(i8* %x) nounwind
628 br label %purple
629
630purple:
631 call void @objc_release(i8* %x) nounwind
632 ret void
633}
634
635; Delete no-ops.
636
637; CHECK: define void @test18(
638; CHECK-NOT: @objc_
639; CHECK: }
640define void @test18() {
641 call i8* @objc_retain(i8* null)
642 call void @objc_release(i8* null)
643 call i8* @objc_autorelease(i8* null)
644 ret void
645}
646
647; Delete no-ops where undef can be assumed to be null.
648
649; CHECK: define void @test18b
650; CHECK-NOT: @objc_
651; CHECK: }
652define void @test18b() {
653 call i8* @objc_retain(i8* undef)
654 call void @objc_release(i8* undef)
655 call i8* @objc_autorelease(i8* undef)
656 ret void
657}
658
659; Replace uses of arguments with uses of return values, to reduce
660; register pressure.
661
662; CHECK: define void @test19(i32* %y) {
663; CHECK: %z = bitcast i32* %y to i8*
664; CHECK: %0 = bitcast i32* %y to i8*
665; CHECK: %1 = tail call i8* @objc_retain(i8* %0)
666; CHECK: call void @use_pointer(i8* %z)
667; CHECK: call void @use_pointer(i8* %z)
668; CHECK: %2 = bitcast i32* %y to i8*
669; CHECK: call void @objc_release(i8* %2)
670; CHECK: ret void
671; CHECK: }
672define void @test19(i32* %y) {
673entry:
674 %x = bitcast i32* %y to i8*
675 %0 = call i8* @objc_retain(i8* %x) nounwind
676 %z = bitcast i32* %y to i8*
677 call void @use_pointer(i8* %z)
678 call void @use_pointer(i8* %z)
679 call void @objc_release(i8* %x)
680 ret void
681}
682
683; Bitcast insertion
684
685; CHECK: define void @test20(
686; CHECK: %tmp1 = tail call i8* @objc_retain(i8* %tmp) nounwind
687; CHECK-NEXT: invoke
688define void @test20(double* %self) {
689if.then12:
690 %tmp = bitcast double* %self to i8*
691 %tmp1 = call i8* @objc_retain(i8* %tmp) nounwind
692 invoke void @invokee()
693 to label %invoke.cont23 unwind label %lpad20
694
695invoke.cont23: ; preds = %if.then12
696 invoke void @invokee()
697 to label %if.end unwind label %lpad20
698
699lpad20: ; preds = %invoke.cont23, %if.then12
700 %tmp502 = phi double* [ undef, %invoke.cont23 ], [ %self, %if.then12 ]
701 unreachable
702
703if.end: ; preds = %invoke.cont23
704 ret void
705}
706
707; Delete a redundant retain,autorelease when forwaring a call result
708; directly to a return value.
709
710; CHECK: define i8* @test21(
711; CHECK: call i8* @returner()
712; CHECK-NEXT: ret i8* %call
713define i8* @test21() {
714entry:
715 %call = call i8* @returner()
716 %0 = call i8* @objc_retain(i8* %call) nounwind
717 %1 = call i8* @objc_autorelease(i8* %0) nounwind
718 ret i8* %1
719}
720
721; Move an objc call up through a phi that has null operands.
722
723; CHECK: define void @test22(
724; CHECK: B:
725; CHECK: %1 = bitcast double* %p to i8*
726; CHECK: call void @objc_release(i8* %1)
727; CHECK: br label %C
728; CHECK: C: ; preds = %B, %A
729; CHECK-NOT: @objc_release
730; CHECK: }
731define void @test22(double* %p, i1 %a) {
732 br i1 %a, label %A, label %B
733A:
734 br label %C
735B:
736 br label %C
737C:
738 %h = phi double* [ null, %A ], [ %p, %B ]
739 %c = bitcast double* %h to i8*
740 call void @objc_release(i8* %c)
741 ret void
742}
743
744; Optimize objc_retainBlock.
745
746; CHECK: define void @test23(
747; CHECK-NOT: @objc_
748; CHECK: }
749%block0 = type { i64, i64, i8*, i8* }
750%block1 = type { i8**, i32, i32, i32 (%struct.__block_literal_1*)*, %block0* }
751%struct.__block_descriptor = type { i64, i64 }
752%struct.__block_literal_1 = type { i8**, i32, i32, i8**, %struct.__block_descriptor* }
753@__block_holder_tmp_1 = external constant %block1
754define void @test23() {
755entry:
756 %0 = call i8* @objc_retainBlock(i8* bitcast (%block1* @__block_holder_tmp_1 to i8*)) nounwind
757 call void @bar(i32 ()* bitcast (%block1* @__block_holder_tmp_1 to i32 ()*))
758 call void @bar(i32 ()* bitcast (%block1* @__block_holder_tmp_1 to i32 ()*))
759 call void @objc_release(i8* bitcast (%block1* @__block_holder_tmp_1 to i8*)) nounwind
760 ret void
761}
762
763; Don't optimize objc_retainBlock.
764
765; CHECK: define void @test23b
766; CHECK: @objc_retainBlock
767; CHECK: @objc_release
768; CHECK: }
769define void @test23b(i8* %p) {
770entry:
771 %0 = call i8* @objc_retainBlock(i8* %p) nounwind
Dan Gohmanbce94fd2011-08-22 17:27:02 +0000772 call void @callee()
John McCalld935e9c2011-06-15 23:37:01 +0000773 call void @use_pointer(i8* %p)
774 call void @objc_release(i8* %p) nounwind
775 ret void
776}
777
778; Any call can decrement a retain count.
779
780; CHECK: define void @test24(
781; CHECK: @objc_retain(i8* %a)
782; CHECK: @objc_release
783; CHECK: }
784define void @test24(i8* %r, i8* %a) {
785 call i8* @objc_retain(i8* %a)
786 call void @use_pointer(i8* %r)
787 %q = load i8* %a
788 call void @objc_release(i8* %a)
789 ret void
790}
791
792; Don't move a retain/release pair if the release can be moved
793; but the retain can't be moved to balance it.
794
795; CHECK: define void @test25(
796; CHECK: entry:
797; CHECK: call i8* @objc_retain(i8* %p)
798; CHECK: true:
799; CHECK: done:
800; CHECK: call void @objc_release(i8* %p)
801; CHECK: }
802define void @test25(i8* %p, i1 %x) {
803entry:
804 %f0 = call i8* @objc_retain(i8* %p)
805 call void @callee()
806 br i1 %x, label %true, label %done
807
808true:
809 store i8 0, i8* %p
810 br label %done
811
812done:
813 call void @objc_release(i8* %p)
814 ret void
815}
816
817; Don't move a retain/release pair if the retain can be moved
818; but the release can't be moved to balance it.
819
820; CHECK: define void @test26(
821; CHECK: entry:
822; CHECK: call i8* @objc_retain(i8* %p)
823; CHECK: true:
824; CHECK: done:
825; CHECK: call void @objc_release(i8* %p)
826; CHECK: }
827define void @test26(i8* %p, i1 %x) {
828entry:
829 %f0 = call i8* @objc_retain(i8* %p)
830 br i1 %x, label %true, label %done
831
832true:
833 call void @callee()
834 br label %done
835
836done:
837 store i8 0, i8* %p
838 call void @objc_release(i8* %p)
839 ret void
840}
841
842; Don't sink the retain,release into the loop.
843
844; CHECK: define void @test27(
845; CHECK: entry:
846; CHECK: call i8* @objc_retain(i8* %p)
847; CHECK: loop:
848; CHECK-NOT: @objc_
849; CHECK: done:
850; CHECK: call void @objc_release
851; CHECK: }
852define void @test27(i8* %p, i1 %x, i1 %y) {
853entry:
854 %f0 = call i8* @objc_retain(i8* %p)
855 br i1 %x, label %loop, label %done
856
857loop:
858 call void @callee()
859 store i8 0, i8* %p
860 br i1 %y, label %done, label %loop
861
862done:
863 call void @objc_release(i8* %p)
864 ret void
865}
866
867; Trivial code motion case: Triangle.
868
869; CHECK: define void @test28(
870; CHECK-NOT: @objc_
871; CHECK: true:
872; CHECK: call i8* @objc_retain(
873; CHECK: call void @callee()
874; CHECK: store
875; CHECK: call void @objc_release
876; CHECK: done:
877; CHECK-NOT: @objc_
878; CHECK: }
879define void @test28(i8* %p, i1 %x) {
880entry:
881 %f0 = call i8* @objc_retain(i8* %p)
882 br i1 %x, label %true, label %done
883
884true:
885 call void @callee()
886 store i8 0, i8* %p
887 br label %done
888
889done:
890 call void @objc_release(i8* %p), !clang.imprecise_release !0
891 ret void
892}
893
894; Trivial code motion case: Triangle, but no metadata. Don't move past
895; unrelated memory references!
896
897; CHECK: define void @test28b
898; CHECK: call i8* @objc_retain(
899; CHECK: true:
900; CHECK-NOT: @objc_
901; CHECK: call void @callee()
902; CHECK-NOT: @objc_
903; CHECK: store
904; CHECK-NOT: @objc_
905; CHECK: done:
906; CHECK: @objc_release
907; CHECK: }
908define void @test28b(i8* %p, i1 %x, i8* noalias %t) {
909entry:
910 %f0 = call i8* @objc_retain(i8* %p)
911 br i1 %x, label %true, label %done
912
913true:
914 call void @callee()
915 store i8 0, i8* %p
916 br label %done
917
918done:
919 store i8 0, i8* %t
920 call void @objc_release(i8* %p)
921 ret void
922}
923
924; Trivial code motion case: Triangle, with metadata. Do move past
925; unrelated memory references! And preserve the metadata.
926
927; CHECK: define void @test28c
928; CHECK-NOT: @objc_
929; CHECK: true:
930; CHECK: call i8* @objc_retain(
931; CHECK: call void @callee()
932; CHECK: store
933; CHECK: call void @objc_release(i8* %p) nounwind, !clang.imprecise_release
934; CHECK: done:
935; CHECK-NOT: @objc_
936; CHECK: }
937define void @test28c(i8* %p, i1 %x, i8* noalias %t) {
938entry:
939 %f0 = call i8* @objc_retain(i8* %p)
940 br i1 %x, label %true, label %done
941
942true:
943 call void @callee()
944 store i8 0, i8* %p
945 br label %done
946
947done:
948 store i8 0, i8* %t
949 call void @objc_release(i8* %p), !clang.imprecise_release !0
950 ret void
951}
952
953; Like test28. but with two releases.
954
955; CHECK: define void @test29(
956; CHECK-NOT: @objc_
957; CHECK: true:
958; CHECK: call i8* @objc_retain(
959; CHECK: call void @callee()
960; CHECK: store
961; CHECK: call void @objc_release
962; CHECK-NOT: @objc_release
963; CHECK: done:
964; CHECK-NOT: @objc_
965; CHECK: ohno:
966; CHECK-NOT: @objc_
967; CHECK: }
968define void @test29(i8* %p, i1 %x, i1 %y) {
969entry:
970 %f0 = call i8* @objc_retain(i8* %p)
971 br i1 %x, label %true, label %done
972
973true:
974 call void @callee()
975 store i8 0, i8* %p
976 br i1 %y, label %done, label %ohno
977
978done:
979 call void @objc_release(i8* %p)
980 ret void
981
982ohno:
983 call void @objc_release(i8* %p)
984 ret void
985}
986
987; Basic case with the use and call in a diamond
988; with an extra release.
989
990; CHECK: define void @test30(
991; CHECK-NOT: @objc_
992; CHECK: true:
993; CHECK: call i8* @objc_retain(
994; CHECK: call void @callee()
995; CHECK: store
996; CHECK: call void @objc_release
997; CHECK-NOT: @objc_release
998; CHECK: false:
999; CHECK-NOT: @objc_
1000; CHECK: done:
1001; CHECK-NOT: @objc_
1002; CHECK: ohno:
1003; CHECK-NOT: @objc_
1004; CHECK: }
1005define void @test30(i8* %p, i1 %x, i1 %y, i1 %z) {
1006entry:
1007 %f0 = call i8* @objc_retain(i8* %p)
1008 br i1 %x, label %true, label %false
1009
1010true:
1011 call void @callee()
1012 store i8 0, i8* %p
1013 br i1 %y, label %done, label %ohno
1014
1015false:
1016 br i1 %z, label %done, label %ohno
1017
1018done:
1019 call void @objc_release(i8* %p)
1020 ret void
1021
1022ohno:
1023 call void @objc_release(i8* %p)
1024 ret void
1025}
1026
1027; Basic case with a mergeable release.
1028
1029; CHECK: define void @test31(
1030; CHECK: call i8* @objc_retain(i8* %p)
1031; CHECK: call void @callee()
1032; CHECK: store
1033; CHECK: call void @objc_release
1034; CHECK-NOT: @objc_release
1035; CHECK: true:
1036; CHECK-NOT: @objc_release
1037; CHECK: false:
1038; CHECK-NOT: @objc_release
1039; CHECK: ret void
1040; CHECK-NOT: @objc_release
1041; CHECK: }
1042define void @test31(i8* %p, i1 %x) {
1043entry:
1044 %f0 = call i8* @objc_retain(i8* %p)
1045 call void @callee()
1046 store i8 0, i8* %p
1047 br i1 %x, label %true, label %false
1048true:
1049 call void @objc_release(i8* %p)
1050 ret void
1051false:
1052 call void @objc_release(i8* %p)
1053 ret void
1054}
1055
1056; Don't consider bitcasts or getelementptrs direct uses.
1057
1058; CHECK: define void @test32(
1059; CHECK-NOT: @objc_
1060; CHECK: true:
1061; CHECK: call i8* @objc_retain(
1062; CHECK: call void @callee()
1063; CHECK: store
1064; CHECK: call void @objc_release
1065; CHECK: done:
1066; CHECK-NOT: @objc_
1067; CHECK: }
1068define void @test32(i8* %p, i1 %x) {
1069entry:
1070 %f0 = call i8* @objc_retain(i8* %p)
1071 br i1 %x, label %true, label %done
1072
1073true:
1074 call void @callee()
1075 store i8 0, i8* %p
1076 br label %done
1077
1078done:
1079 %g = bitcast i8* %p to i8*
1080 %h = getelementptr i8* %g, i64 0
1081 call void @objc_release(i8* %g)
1082 ret void
1083}
1084
1085; Do consider icmps to be direct uses.
1086
1087; CHECK: define void @test33(
1088; CHECK-NOT: @objc_
1089; CHECK: true:
1090; CHECK: call i8* @objc_retain(
1091; CHECK: call void @callee()
1092; CHECK: icmp
1093; CHECK: call void @objc_release
1094; CHECK: done:
1095; CHECK-NOT: @objc_
1096; CHECK: }
1097define void @test33(i8* %p, i1 %x, i8* %y) {
1098entry:
1099 %f0 = call i8* @objc_retain(i8* %p)
1100 br i1 %x, label %true, label %done
1101
1102true:
1103 call void @callee()
1104 %v = icmp eq i8* %p, %y
1105 br label %done
1106
1107done:
1108 %g = bitcast i8* %p to i8*
1109 %h = getelementptr i8* %g, i64 0
1110 call void @objc_release(i8* %g)
1111 ret void
1112}
1113
1114; Delete retain,release if there's just a possible dec.
1115
1116; CHECK: define void @test34(
1117; CHECK-NOT: @objc_
1118; CHECK: }
1119define void @test34(i8* %p, i1 %x, i8* %y) {
1120entry:
1121 %f0 = call i8* @objc_retain(i8* %p)
1122 br i1 %x, label %true, label %done
1123
1124true:
1125 call void @callee()
1126 br label %done
1127
1128done:
1129 %g = bitcast i8* %p to i8*
1130 %h = getelementptr i8* %g, i64 0
1131 call void @objc_release(i8* %g)
1132 ret void
1133}
1134
1135; Delete retain,release if there's just a use.
1136
1137; CHECK: define void @test35(
1138; CHECK-NOT: @objc_
1139; CHECK: }
1140define void @test35(i8* %p, i1 %x, i8* %y) {
1141entry:
1142 %f0 = call i8* @objc_retain(i8* %p)
1143 br i1 %x, label %true, label %done
1144
1145true:
1146 %v = icmp eq i8* %p, %y
1147 br label %done
1148
1149done:
1150 %g = bitcast i8* %p to i8*
1151 %h = getelementptr i8* %g, i64 0
1152 call void @objc_release(i8* %g)
1153 ret void
1154}
1155
1156; Delete a retain,release if there's no actual use.
1157
1158; CHECK: define void @test36(
1159; CHECK-NOT: @objc_
1160; CHECK: call void @callee()
1161; CHECK-NOT: @objc_
1162; CHECK: call void @callee()
1163; CHECK-NOT: @objc_
1164; CHECK: }
1165define void @test36(i8* %p) {
1166entry:
1167 call i8* @objc_retain(i8* %p)
1168 call void @callee()
1169 call void @callee()
1170 call void @objc_release(i8* %p)
1171 ret void
1172}
1173
1174; Like test36, but with metadata.
1175
1176; CHECK: define void @test37(
1177; CHECK-NOT: @objc_
1178; CHECK: }
1179define void @test37(i8* %p) {
1180entry:
1181 call i8* @objc_retain(i8* %p)
1182 call void @callee()
1183 call void @callee()
1184 call void @objc_release(i8* %p), !clang.imprecise_release !0
1185 ret void
1186}
1187
1188; Be aggressive about analyzing phis to eliminate possible uses.
1189
1190; CHECK: define void @test38(
1191; CHECK-NOT: @objc_
1192; CHECK: }
1193define void @test38(i8* %p, i1 %u, i1 %m, i8* %z, i8* %y, i8* %x, i8* %w) {
1194entry:
1195 call i8* @objc_retain(i8* %p)
1196 br i1 %u, label %true, label %false
1197true:
1198 br i1 %m, label %a, label %b
1199false:
1200 br i1 %m, label %c, label %d
1201a:
1202 br label %e
1203b:
1204 br label %e
1205c:
1206 br label %f
1207d:
1208 br label %f
1209e:
1210 %j = phi i8* [ %z, %a ], [ %y, %b ]
1211 br label %g
1212f:
1213 %k = phi i8* [ %w, %c ], [ %x, %d ]
1214 br label %g
1215g:
1216 %h = phi i8* [ %j, %e ], [ %k, %f ]
1217 call void @use_pointer(i8* %h)
1218 call void @objc_release(i8* %p), !clang.imprecise_release !0
1219 ret void
1220}
1221
1222; Delete retain,release pairs around loops.
1223
1224; CHECK: define void @test39(
1225; CHECK_NOT: @objc_
1226; CHECK: }
1227define void @test39(i8* %p) {
1228entry:
1229 %0 = call i8* @objc_retain(i8* %p)
1230 br label %loop
1231
1232loop: ; preds = %loop, %entry
1233 br i1 undef, label %loop, label %exit
1234
1235exit: ; preds = %loop
1236 call void @objc_release(i8* %0), !clang.imprecise_release !0
1237 ret void
1238}
1239
1240; Delete retain,release pairs around loops containing uses.
1241
1242; CHECK: define void @test39b(
1243; CHECK_NOT: @objc_
1244; CHECK: }
1245define void @test39b(i8* %p) {
1246entry:
1247 %0 = call i8* @objc_retain(i8* %p)
1248 br label %loop
1249
1250loop: ; preds = %loop, %entry
1251 store i8 0, i8* %0
1252 br i1 undef, label %loop, label %exit
1253
1254exit: ; preds = %loop
1255 call void @objc_release(i8* %0), !clang.imprecise_release !0
1256 ret void
1257}
1258
1259; Delete retain,release pairs around loops containing potential decrements.
1260
1261; CHECK: define void @test39c(
1262; CHECK_NOT: @objc_
1263; CHECK: }
1264define void @test39c(i8* %p) {
1265entry:
1266 %0 = call i8* @objc_retain(i8* %p)
1267 br label %loop
1268
1269loop: ; preds = %loop, %entry
1270 call void @use_pointer(i8* %0)
1271 br i1 undef, label %loop, label %exit
1272
1273exit: ; preds = %loop
1274 call void @objc_release(i8* %0), !clang.imprecise_release !0
1275 ret void
1276}
1277
1278; Delete retain,release pairs around loops even if
1279; the successors are in a different order.
1280
1281; CHECK: define void @test40(
1282; CHECK_NOT: @objc_
1283; CHECK: }
1284define void @test40(i8* %p) {
1285entry:
1286 %0 = call i8* @objc_retain(i8* %p)
1287 br label %loop
1288
1289loop: ; preds = %loop, %entry
1290 call void @use_pointer(i8* %0)
1291 br i1 undef, label %exit, label %loop
1292
1293exit: ; preds = %loop
1294 call void @objc_release(i8* %0), !clang.imprecise_release !0
1295 ret void
1296}
1297
1298; Do the known-incremented retain+release elimination even if the pointer
1299; is also autoreleased.
1300
1301; CHECK: define void @test42(
1302; CHECK-NEXT: entry:
1303; CHECK-NEXT: call i8* @objc_retain(i8* %p)
1304; CHECK-NEXT: call i8* @objc_autorelease(i8* %p)
1305; CHECK-NEXT: call void @use_pointer(i8* %p)
1306; CHECK-NEXT: call void @use_pointer(i8* %p)
1307; CHECK-NEXT: ret void
1308; CHECK-NEXT: }
1309define void @test42(i8* %p) {
1310entry:
1311 call i8* @objc_retain(i8* %p)
1312 call i8* @objc_autorelease(i8* %p)
1313 call i8* @objc_retain(i8* %p)
1314 call void @use_pointer(i8* %p)
1315 call void @use_pointer(i8* %p)
1316 call void @objc_release(i8* %p)
1317 ret void
1318}
1319
1320; Don't the known-incremented retain+release elimination if the pointer is
1321; autoreleased and there's an autoreleasePoolPop.
1322
1323; CHECK: define void @test43(
1324; CHECK-NEXT: entry:
1325; CHECK-NEXT: call i8* @objc_retain(i8* %p)
1326; CHECK-NEXT: call i8* @objc_autorelease(i8* %p)
1327; CHECK-NEXT: call i8* @objc_retain
1328; CHECK-NEXT: call void @use_pointer(i8* %p)
1329; CHECK-NEXT: call void @use_pointer(i8* %p)
1330; CHECK-NEXT: call void @objc_autoreleasePoolPop(i8* undef)
1331; CHECK-NEXT: call void @objc_release
1332; CHECK-NEXT: ret void
1333; CHECK-NEXT: }
1334define void @test43(i8* %p) {
1335entry:
1336 call i8* @objc_retain(i8* %p)
1337 call i8* @objc_autorelease(i8* %p)
1338 call i8* @objc_retain(i8* %p)
1339 call void @use_pointer(i8* %p)
1340 call void @use_pointer(i8* %p)
1341 call void @objc_autoreleasePoolPop(i8* undef)
1342 call void @objc_release(i8* %p)
1343 ret void
1344}
1345
1346; Do the known-incremented retain+release elimination if the pointer is
1347; autoreleased and there's an autoreleasePoolPush.
1348
1349; CHECK: define void @test43b
1350; CHECK-NEXT: entry:
1351; CHECK-NEXT: call i8* @objc_retain(i8* %p)
1352; CHECK-NEXT: call i8* @objc_autorelease(i8* %p)
1353; CHECK-NEXT: call void @use_pointer(i8* %p)
1354; CHECK-NEXT: call void @use_pointer(i8* %p)
1355; CHECK-NEXT: call void @objc_autoreleasePoolPush()
1356; CHECK-NEXT: ret void
1357; CHECK-NEXT: }
1358define void @test43b(i8* %p) {
1359entry:
1360 call i8* @objc_retain(i8* %p)
1361 call i8* @objc_autorelease(i8* %p)
1362 call i8* @objc_retain(i8* %p)
1363 call void @use_pointer(i8* %p)
1364 call void @use_pointer(i8* %p)
1365 call void @objc_autoreleasePoolPush()
1366 call void @objc_release(i8* %p)
1367 ret void
1368}
1369
1370; Do retain+release elimination for non-provenance pointers.
1371
1372; CHECK: define void @test44(
1373; CHECK-NOT: objc_
1374; CHECK: }
1375define void @test44(i8** %pp) {
1376 %p = load i8** %pp
1377 %q = call i8* @objc_retain(i8* %p)
1378 call void @objc_release(i8* %q)
1379 ret void
1380}
1381
1382; Don't delete retain+release with an unknown-provenance
1383; may-alias objc_release between them.
1384
1385; CHECK: define void @test45(
1386; CHECK: call i8* @objc_retain(i8* %p)
1387; CHECK: call void @objc_release(i8* %q)
1388; CHECK: call void @use_pointer(i8* %p)
1389; CHECK: call void @objc_release(i8* %p)
1390define void @test45(i8** %pp, i8** %qq) {
1391 %p = load i8** %pp
1392 %q = load i8** %qq
1393 call i8* @objc_retain(i8* %p)
1394 call void @objc_release(i8* %q)
1395 call void @use_pointer(i8* %p)
1396 call void @objc_release(i8* %p)
1397 ret void
1398}
1399
1400; Don't delete retain and autorelease here.
1401
1402; CHECK: define void @test46(
1403; CHECK: tail call i8* @objc_retain(i8* %p) nounwind
1404; CHECK: true:
1405; CHECK: tail call i8* @objc_autorelease(i8* %p) nounwind
1406define void @test46(i8* %p, i1 %a) {
1407entry:
1408 call i8* @objc_retain(i8* %p)
1409 br i1 %a, label %true, label %false
1410
1411true:
1412 call i8* @objc_autorelease(i8* %p)
1413 call void @use_pointer(i8* %p)
1414 ret void
1415
1416false:
1417 ret void
1418}
1419
1420; Delete no-op cast calls.
1421
1422; CHECK: define i8* @test47(
1423; CHECK-NOT: call
1424; CHECK: ret i8* %p
1425define i8* @test47(i8* %p) nounwind {
1426 %x = call i8* @objc_retainedObject(i8* %p)
1427 ret i8* %x
1428}
1429
1430; Delete no-op cast calls.
1431
1432; CHECK: define i8* @test48(
1433; CHECK-NOT: call
1434; CHECK: ret i8* %p
1435define i8* @test48(i8* %p) nounwind {
1436 %x = call i8* @objc_unretainedObject(i8* %p)
1437 ret i8* %x
1438}
1439
1440; Delete no-op cast calls.
1441
1442; CHECK: define i8* @test49(
1443; CHECK-NOT: call
1444; CHECK: ret i8* %p
1445define i8* @test49(i8* %p) nounwind {
1446 %x = call i8* @objc_unretainedPointer(i8* %p)
1447 ret i8* %x
1448}
1449
1450; Do delete retain+release with intervening stores of the
1451; address value;
1452
1453; CHECK: define void @test50(
1454; CHECK-NOT: @objc_
1455; CHECK: }
1456define void @test50(i8* %p, i8** %pp) {
1457 call i8* @objc_retain(i8* %p)
1458 call void @callee()
1459 store i8* %p, i8** %pp
1460 call void @objc_release(i8* %p)
1461 ret void
1462}
1463
1464; Don't delete retain+release with intervening stores through the
1465; address value.
1466
1467; CHECK: define void @test51(
1468; CHECK: call i8* @objc_retain(i8* %p)
1469; CHECK: call void @objc_release(i8* %p)
1470define void @test51(i8* %p) {
1471 call i8* @objc_retain(i8* %p)
1472 call void @callee()
1473 store i8 0, i8* %p
1474 call void @objc_release(i8* %p)
1475 ret void
1476}
1477
1478; Don't delete retain+release with intervening use of a pointer of
1479; unknown provenance.
1480
1481; CHECK: define void @test52(
1482; CHECK: call i8* @objc_retain
1483; CHECK: call void @callee()
1484; CHECK: call void @use_pointer(i8* %z)
1485; CHECK: call void @objc_release
1486define void @test52(i8** %zz, i8** %pp) {
1487 %p = load i8** %pp
1488 %1 = call i8* @objc_retain(i8* %p)
1489 call void @callee()
1490 %z = load i8** %zz
1491 call void @use_pointer(i8* %z)
1492 call void @objc_release(i8* %p)
1493 ret void
1494}
1495
1496; Like test52, but the pointer has function type, so it's assumed to
1497; be not reference counted.
1498
1499; CHECK: define void @test53(
1500; CHECK-NOT: @objc_
1501; CHECK: }
1502define void @test53(void ()** %zz, i8** %pp) {
1503 %p = load i8** %pp
1504 %1 = call i8* @objc_retain(i8* %p)
1505 call void @callee()
1506 %z = load void ()** %zz
1507 call void @callee_fnptr(void ()* %z)
1508 call void @objc_release(i8* %p)
1509 ret void
1510}
1511
1512; Convert autorelease to release if the value is unused.
1513
1514; CHECK: define void @test54(
1515; CHECK: call i8* @returner()
1516; CHECK-NEXT: call void @objc_release(i8* %t) nounwind, !clang.imprecise_release !0
1517; CHECK-NEXT: ret void
1518define void @test54() {
1519 %t = call i8* @returner()
1520 call i8* @objc_autorelease(i8* %t)
1521 ret void
1522}
1523
1524; Nested retain+release pairs. Delete them both.
1525
1526; CHECK: define void @test55(
1527; CHECK-NOT: @objc
1528; CHECK: }
1529define void @test55(i8* %x) {
1530entry:
1531 %0 = call i8* @objc_retain(i8* %x) nounwind
1532 %1 = call i8* @objc_retain(i8* %x) nounwind
1533 call void @objc_release(i8* %x) nounwind
1534 call void @objc_release(i8* %x) nounwind
1535 ret void
1536}
1537
1538; Nested retain+release pairs where the inner pair depends
1539; on the outer pair to be removed, and then the outer pair
1540; can be partially eliminated. Plus an extra outer pair to
1541; eliminate, for fun.
1542
1543; CHECK: define void @test56(
1544; CHECK-NOT: @objc
1545; CHECK: if.then:
1546; CHECK-NEXT: %0 = tail call i8* @objc_retain(i8* %x) nounwind
1547; CHECK-NEXT: tail call void @use_pointer(i8* %x)
1548; CHECK-NEXT: tail call void @use_pointer(i8* %x)
1549; CHECK-NEXT: tail call void @objc_release(i8* %x) nounwind, !clang.imprecise_release !0
1550; CHECK-NEXT: br label %if.end
1551; CHECK-NOT: @objc
1552; CHECK: }
1553define void @test56(i8* %x, i32 %n) {
1554entry:
1555 %0 = tail call i8* @objc_retain(i8* %x) nounwind
1556 %1 = tail call i8* @objc_retain(i8* %0) nounwind
1557 %tobool = icmp eq i32 %n, 0
1558 br i1 %tobool, label %if.end, label %if.then
1559
1560if.then: ; preds = %entry
1561 %2 = tail call i8* @objc_retain(i8* %1) nounwind
1562 tail call void @use_pointer(i8* %2)
1563 tail call void @use_pointer(i8* %2)
1564 tail call void @objc_release(i8* %2) nounwind, !clang.imprecise_release !0
1565 br label %if.end
1566
1567if.end: ; preds = %entry, %if.then
1568 tail call void @objc_release(i8* %1) nounwind, !clang.imprecise_release !0
1569 tail call void @objc_release(i8* %0) nounwind, !clang.imprecise_release !0
1570 ret void
1571}
1572
Dan Gohmanb3894012011-08-19 00:26:36 +00001573; When there are adjacent retain+release pairs, the first one is
1574; known unnecessary because the presence of the second one means that
1575; the first one won't be deleting the object.
1576
1577; CHECK: define void @test57(
1578; CHECK-NEXT: entry:
1579; CHECK-NEXT: call void @use_pointer(i8* %x)
1580; CHECK-NEXT: call void @use_pointer(i8* %x)
1581; CHECK-NEXT: %0 = tail call i8* @objc_retain(i8* %x) nounwind
1582; CHECK-NEXT: call void @use_pointer(i8* %x)
1583; CHECK-NEXT: call void @use_pointer(i8* %x)
1584; CHECK-NEXT: call void @objc_release(i8* %x) nounwind
1585; CHECK-NEXT: ret void
1586; CHECK-NEXT: }
1587define void @test57(i8* %x) nounwind {
1588entry:
1589 call i8* @objc_retain(i8* %x) nounwind
1590 call void @use_pointer(i8* %x)
1591 call void @use_pointer(i8* %x)
1592 call void @objc_release(i8* %x) nounwind
1593 call i8* @objc_retain(i8* %x) nounwind
1594 call void @use_pointer(i8* %x)
1595 call void @use_pointer(i8* %x)
1596 call void @objc_release(i8* %x) nounwind
1597 ret void
1598}
1599
1600; An adjacent retain+release pair is sufficient even if it will be
1601; removed itself.
1602
1603; CHECK: define void @test58(
1604; CHECK-NEXT: entry:
1605; CHECK-NEXT: call void @use_pointer(i8* %x)
1606; CHECK-NEXT: call void @use_pointer(i8* %x)
1607; CHECK-NEXT: ret void
1608; CHECK-NEXT: }
1609define void @test58(i8* %x) nounwind {
1610entry:
1611 call i8* @objc_retain(i8* %x) nounwind
1612 call void @use_pointer(i8* %x)
1613 call void @use_pointer(i8* %x)
1614 call void @objc_release(i8* %x) nounwind
1615 call i8* @objc_retain(i8* %x) nounwind
1616 call void @objc_release(i8* %x) nounwind
1617 ret void
1618}
1619
1620; Don't delete the second retain+release pair in an adjacent set.
1621
1622; CHECK: define void @test59(
1623; CHECK-NEXT: entry:
1624; CHECK-NEXT: %0 = tail call i8* @objc_retain(i8* %x) nounwind
1625; CHECK-NEXT: call void @use_pointer(i8* %x)
1626; CHECK-NEXT: call void @use_pointer(i8* %x)
1627; CHECK-NEXT: call void @objc_release(i8* %x) nounwind
1628; CHECK-NEXT: ret void
1629; CHECK-NEXT: }
1630define void @test59(i8* %x) nounwind {
1631entry:
1632 %a = call i8* @objc_retain(i8* %x) nounwind
1633 call void @objc_release(i8* %x) nounwind
1634 %b = call i8* @objc_retain(i8* %x) nounwind
1635 call void @use_pointer(i8* %x)
1636 call void @use_pointer(i8* %x)
1637 call void @objc_release(i8* %x) nounwind
1638 ret void
1639}
1640
Dan Gohman56e1cef2011-08-22 17:29:11 +00001641; Constant pointers to objects don't need reference counting.
1642
1643@constptr = external constant i8*
1644@something = external global i8*
1645
1646; CHECK: define void @test60(
1647; CHECK-NOT: @objc_
1648; CHECK: }
1649define void @test60() {
1650 %t = load i8** @constptr
1651 %s = load i8** @something
1652 call i8* @objc_retain(i8* %s)
1653 call void @callee()
1654 call void @use_pointer(i8* %t)
1655 call void @objc_release(i8* %s)
1656 ret void
1657}
1658
1659; Constant pointers to objects don't need to be considered related to other
1660; pointers.
1661
1662; CHECK: define void @test61(
1663; CHECK-NOT: @objc_
1664; CHECK: }
1665define void @test61() {
1666 %t = load i8** @constptr
1667 call i8* @objc_retain(i8* %t)
1668 call void @callee()
1669 call void @use_pointer(i8* %t)
1670 call void @objc_release(i8* %t)
1671 ret void
1672}
1673
John McCalld935e9c2011-06-15 23:37:01 +00001674declare void @bar(i32 ()*)
1675
1676; A few real-world testcases.
1677
1678@.str4 = private unnamed_addr constant [33 x i8] c"-[A z] = { %f, %f, { %f, %f } }\0A\00"
1679@"OBJC_IVAR_$_A.myZ" = global i64 20, section "__DATA, __objc_const", align 8
1680declare i32 @printf(i8* nocapture, ...) nounwind
1681declare i32 @puts(i8* nocapture) nounwind
1682@str = internal constant [16 x i8] c"-[ Top0 _getX ]\00"
1683
1684; CHECK: @"\01-[A z]"
1685; CHECK-NOT: @objc_
1686; CHECK: }
1687
1688define {<2 x float>, <2 x float>} @"\01-[A z]"({}* %self, i8* nocapture %_cmd) nounwind {
1689invoke.cont:
1690 %0 = bitcast {}* %self to i8*
1691 %1 = tail call i8* @objc_retain(i8* %0) nounwind
1692 tail call void @llvm.dbg.value(metadata !{{}* %self}, i64 0, metadata !0)
1693 tail call void @llvm.dbg.value(metadata !{{}* %self}, i64 0, metadata !0)
1694 %ivar = load i64* @"OBJC_IVAR_$_A.myZ", align 8
1695 %add.ptr = getelementptr i8* %0, i64 %ivar
1696 %tmp1 = bitcast i8* %add.ptr to float*
1697 %tmp2 = load float* %tmp1, align 4
1698 %conv = fpext float %tmp2 to double
1699 %add.ptr.sum = add i64 %ivar, 4
1700 %tmp6 = getelementptr inbounds i8* %0, i64 %add.ptr.sum
1701 %2 = bitcast i8* %tmp6 to float*
1702 %tmp7 = load float* %2, align 4
1703 %conv8 = fpext float %tmp7 to double
1704 %add.ptr.sum36 = add i64 %ivar, 8
1705 %tmp12 = getelementptr inbounds i8* %0, i64 %add.ptr.sum36
1706 %arrayidx = bitcast i8* %tmp12 to float*
1707 %tmp13 = load float* %arrayidx, align 4
1708 %conv14 = fpext float %tmp13 to double
1709 %tmp12.sum = add i64 %ivar, 12
1710 %arrayidx19 = getelementptr inbounds i8* %0, i64 %tmp12.sum
1711 %3 = bitcast i8* %arrayidx19 to float*
1712 %tmp20 = load float* %3, align 4
1713 %conv21 = fpext float %tmp20 to double
1714 %call = tail call i32 (i8*, ...)* @printf(i8* getelementptr inbounds ([33 x i8]* @.str4, i64 0, i64 0), double %conv, double %conv8, double %conv14, double %conv21)
1715 %ivar23 = load i64* @"OBJC_IVAR_$_A.myZ", align 8
1716 %add.ptr24 = getelementptr i8* %0, i64 %ivar23
1717 %4 = bitcast i8* %add.ptr24 to i128*
1718 %srcval = load i128* %4, align 4
1719 tail call void @objc_release(i8* %0) nounwind
1720 %tmp29 = trunc i128 %srcval to i64
1721 %tmp30 = bitcast i64 %tmp29 to <2 x float>
1722 %tmp31 = insertvalue {<2 x float>, <2 x float>} undef, <2 x float> %tmp30, 0
1723 %tmp32 = lshr i128 %srcval, 64
1724 %tmp33 = trunc i128 %tmp32 to i64
1725 %tmp34 = bitcast i64 %tmp33 to <2 x float>
1726 %tmp35 = insertvalue {<2 x float>, <2 x float>} %tmp31, <2 x float> %tmp34, 1
1727 ret {<2 x float>, <2 x float>} %tmp35
1728}
1729
1730; CHECK: @"\01-[Top0 _getX]"
1731; CHECK-NOT: @objc_
1732; CHECK: }
1733
1734define i32 @"\01-[Top0 _getX]"({}* %self, i8* nocapture %_cmd) nounwind {
1735invoke.cont:
1736 %0 = bitcast {}* %self to i8*
1737 %1 = tail call i8* @objc_retain(i8* %0) nounwind
1738 %puts = tail call i32 @puts(i8* getelementptr inbounds ([16 x i8]* @str, i64 0, i64 0))
1739 tail call void @objc_release(i8* %0) nounwind
1740 ret i32 0
1741}
1742
1743@"\01L_OBJC_METH_VAR_NAME_" = internal global [5 x i8] c"frob\00", section "__TEXT,__cstring,cstring_literals", align 1@"\01L_OBJC_SELECTOR_REFERENCES_" = internal global i8* getelementptr inbounds ([5 x i8]* @"\01L_OBJC_METH_VAR_NAME_", i64 0, i64 0), section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
1744@"\01L_OBJC_IMAGE_INFO" = internal constant [2 x i32] [i32 0, i32 16], section "__DATA, __objc_imageinfo, regular, no_dead_strip"
1745@llvm.used = appending global [3 x i8*] [i8* getelementptr inbounds ([5 x i8]* @"\01L_OBJC_METH_VAR_NAME_", i32 0, i32 0), i8* bitcast (i8** @"\01L_OBJC_SELECTOR_REFERENCES_" to i8*), i8* bitcast ([2 x i32]* @"\01L_OBJC_IMAGE_INFO" to i8*)], section "llvm.metadata"
1746
1747; A simple loop. Eliminate the retain and release inside of it!
1748
1749; CHECK: define void @loop
1750; CHECK: for.body:
1751; CHECK-NOT: @objc_
1752; CHECK: @objc_msgSend
1753; CHECK-NOT: @objc_
1754; CHECK: for.end:
1755define void @loop(i8* %x, i64 %n) {
1756entry:
1757 %0 = tail call i8* @objc_retain(i8* %x) nounwind
1758 %cmp9 = icmp sgt i64 %n, 0
1759 br i1 %cmp9, label %for.body, label %for.end
1760
1761for.body: ; preds = %entry, %for.body
1762 %i.010 = phi i64 [ %inc, %for.body ], [ 0, %entry ]
1763 %1 = tail call i8* @objc_retain(i8* %x) nounwind
1764 %tmp5 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_", align 8
1765 %call = tail call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %1, i8* %tmp5)
1766 tail call void @objc_release(i8* %1) nounwind, !clang.imprecise_release !0
1767 %inc = add nsw i64 %i.010, 1
1768 %exitcond = icmp eq i64 %inc, %n
1769 br i1 %exitcond, label %for.end, label %for.body
1770
1771for.end: ; preds = %for.body, %entry
1772 tail call void @objc_release(i8* %x) nounwind, !clang.imprecise_release !0
1773 ret void
1774}
1775
1776; ObjCARCOpt can delete the retain,release on self.
1777
1778; CHECK: define void @TextEditTest
1779; CHECK-NOT: call i8* @objc_retain(i8* %tmp7)
1780; CHECK: }
1781
1782%0 = type { i8* (i8*, %struct._message_ref_t*, ...)*, i8* }
1783%1 = type opaque
1784%2 = type opaque
1785%3 = type opaque
1786%4 = type opaque
1787%5 = type opaque
1788%struct.NSConstantString = type { i32*, i32, i8*, i64 }
1789%struct._NSRange = type { i64, i64 }
1790%struct.__CFString = type opaque
1791%struct.__method_list_t = type { i32, i32, [0 x %struct._objc_method] }
1792%struct._class_ro_t = type { i32, i32, i32, i8*, i8*, %struct.__method_list_t*, %struct._objc_protocol_list*, %struct._ivar_list_t*, i8*, %struct._prop_list_t* }
1793%struct._class_t = type { %struct._class_t*, %struct._class_t*, %struct._objc_cache*, i8* (i8*, i8*)**, %struct._class_ro_t* }
1794%struct._ivar_list_t = type { i32, i32, [0 x %struct._ivar_t] }
1795%struct._ivar_t = type { i64*, i8*, i8*, i32, i32 }
1796%struct._message_ref_t = type { i8*, i8* }
1797%struct._objc_cache = type opaque
1798%struct._objc_method = type { i8*, i8*, i8* }
1799%struct._objc_protocol_list = type { i64, [0 x %struct._protocol_t*] }
1800%struct._prop_list_t = type { i32, i32, [0 x %struct._message_ref_t] }
1801%struct._protocol_t = type { i8*, i8*, %struct._objc_protocol_list*, %struct.__method_list_t*, %struct.__method_list_t*, %struct.__method_list_t*, %struct.__method_list_t*, %struct._prop_list_t*, i32, i32 }
1802
1803@"\01L_OBJC_CLASSLIST_REFERENCES_$_17" = external hidden global %struct._class_t*, section "__DATA, __objc_classrefs, regular, no_dead_strip", align 8
1804@kUTTypePlainText = external constant %struct.__CFString*
1805@"\01L_OBJC_SELECTOR_REFERENCES_19" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
1806@"\01L_OBJC_SELECTOR_REFERENCES_21" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
1807@"\01L_OBJC_SELECTOR_REFERENCES_23" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
1808@"\01L_OBJC_SELECTOR_REFERENCES_25" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
1809@"\01L_OBJC_CLASSLIST_REFERENCES_$_26" = external hidden global %struct._class_t*, section "__DATA, __objc_classrefs, regular, no_dead_strip", align 8
1810@"\01L_OBJC_SELECTOR_REFERENCES_28" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
1811@"\01L_OBJC_CLASSLIST_REFERENCES_$_29" = external hidden global %struct._class_t*, section "__DATA, __objc_classrefs, regular, no_dead_strip", align 8
1812@"\01L_OBJC_SELECTOR_REFERENCES_31" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
1813@"\01L_OBJC_SELECTOR_REFERENCES_33" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
1814@"\01L_OBJC_SELECTOR_REFERENCES_35" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
1815@"\01L_OBJC_SELECTOR_REFERENCES_37" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
1816@"\01L_OBJC_CLASSLIST_REFERENCES_$_38" = external hidden global %struct._class_t*, section "__DATA, __objc_classrefs, regular, no_dead_strip", align 8
1817@"\01L_OBJC_SELECTOR_REFERENCES_40" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
1818@"\01L_OBJC_SELECTOR_REFERENCES_42" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
1819@_unnamed_cfstring_44 = external hidden constant %struct.NSConstantString, section "__DATA,__cfstring"
1820@"\01L_OBJC_SELECTOR_REFERENCES_46" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
1821@"\01L_OBJC_SELECTOR_REFERENCES_48" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
1822@"\01l_objc_msgSend_fixup_isEqual_" = external hidden global %0, section "__DATA, __objc_msgrefs, coalesced", align 16
1823@"\01L_OBJC_CLASSLIST_REFERENCES_$_50" = external hidden global %struct._class_t*, section "__DATA, __objc_classrefs, regular, no_dead_strip", align 8
1824@NSCocoaErrorDomain = external constant %1*
1825@"\01L_OBJC_CLASSLIST_REFERENCES_$_51" = external hidden global %struct._class_t*, section "__DATA, __objc_classrefs, regular, no_dead_strip", align 8
1826@NSFilePathErrorKey = external constant %1*
1827@"\01L_OBJC_SELECTOR_REFERENCES_53" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
1828@"\01L_OBJC_SELECTOR_REFERENCES_55" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
1829@"\01L_OBJC_CLASSLIST_REFERENCES_$_56" = external hidden global %struct._class_t*, section "__DATA, __objc_classrefs, regular, no_dead_strip", align 8
1830@"\01L_OBJC_SELECTOR_REFERENCES_58" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
1831@"\01L_OBJC_SELECTOR_REFERENCES_60" = external hidden global i8*, section "__DATA, __objc_selrefs, literal_pointers, no_dead_strip"
1832
1833declare %1* @truncatedString(%1*, i64)
1834define void @TextEditTest(%2* %self, %3* %pboard) {
1835entry:
1836 %err = alloca %4*, align 8
1837 %tmp7 = bitcast %2* %self to i8*
1838 %tmp8 = call i8* @objc_retain(i8* %tmp7) nounwind
1839 store %4* null, %4** %err, align 8
1840 %tmp1 = load %struct._class_t** @"\01L_OBJC_CLASSLIST_REFERENCES_$_17", align 8
1841 %tmp2 = load %struct.__CFString** @kUTTypePlainText, align 8
1842 %tmp3 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_19", align 8
1843 %tmp4 = bitcast %struct._class_t* %tmp1 to i8*
1844 %call5 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %tmp4, i8* %tmp3, %struct.__CFString* %tmp2)
1845 %tmp5 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_21", align 8
1846 %tmp6 = bitcast %3* %pboard to i8*
1847 %call76 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %tmp6, i8* %tmp5, i8* %call5)
1848 %tmp9 = call i8* @objc_retain(i8* %call76) nounwind
1849 %tobool = icmp eq i8* %tmp9, null
1850 br i1 %tobool, label %end, label %land.lhs.true
1851
1852land.lhs.true: ; preds = %entry
1853 %tmp11 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_23", align 8
1854 %call137 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %tmp6, i8* %tmp11, i8* %tmp9)
1855 %tmp = bitcast i8* %call137 to %1*
1856 %tmp10 = call i8* @objc_retain(i8* %call137) nounwind
1857 call void @objc_release(i8* null) nounwind
1858 %tmp12 = call i8* @objc_retain(i8* %call137) nounwind
1859 call void @objc_release(i8* null) nounwind
1860 %tobool16 = icmp eq i8* %call137, null
1861 br i1 %tobool16, label %end, label %if.then
1862
1863if.then: ; preds = %land.lhs.true
1864 %tmp19 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_25", align 8
1865 %call21 = call signext i8 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8 (i8*, i8*)*)(i8* %call137, i8* %tmp19)
1866 %tobool22 = icmp eq i8 %call21, 0
1867 br i1 %tobool22, label %if.then44, label %land.lhs.true23
1868
1869land.lhs.true23: ; preds = %if.then
1870 %tmp24 = load %struct._class_t** @"\01L_OBJC_CLASSLIST_REFERENCES_$_26", align 8
1871 %tmp26 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_28", align 8
1872 %tmp27 = bitcast %struct._class_t* %tmp24 to i8*
1873 %call2822 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %tmp27, i8* %tmp26, i8* %call137)
1874 %tmp13 = bitcast i8* %call2822 to %5*
1875 %tmp14 = call i8* @objc_retain(i8* %call2822) nounwind
1876 call void @objc_release(i8* null) nounwind
1877 %tobool30 = icmp eq i8* %call2822, null
1878 br i1 %tobool30, label %if.then44, label %if.end
1879
1880if.end: ; preds = %land.lhs.true23
1881 %tmp32 = load %struct._class_t** @"\01L_OBJC_CLASSLIST_REFERENCES_$_29", align 8
1882 %tmp33 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_31", align 8
1883 %tmp34 = bitcast %struct._class_t* %tmp32 to i8*
1884 %call35 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %tmp34, i8* %tmp33)
1885 %tmp37 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_33", align 8
1886 %call3923 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %call35, i8* %tmp37, i8* %call2822, i32 signext 1, %4** %err)
1887 %cmp = icmp eq i8* %call3923, null
1888 br i1 %cmp, label %if.then44, label %end
1889
1890if.then44: ; preds = %if.end, %land.lhs.true23, %if.then
1891 %url.025 = phi %5* [ %tmp13, %if.end ], [ %tmp13, %land.lhs.true23 ], [ null, %if.then ]
1892 %tmp49 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_35", align 8
1893 %call51 = call %struct._NSRange bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to %struct._NSRange (i8*, i8*, i64, i64)*)(i8* %call137, i8* %tmp49, i64 0, i64 0)
1894 %call513 = extractvalue %struct._NSRange %call51, 0
1895 %call514 = extractvalue %struct._NSRange %call51, 1
1896 %tmp52 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_37", align 8
1897 %call548 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %call137, i8* %tmp52, i64 %call513, i64 %call514)
1898 %tmp55 = load %struct._class_t** @"\01L_OBJC_CLASSLIST_REFERENCES_$_38", align 8
1899 %tmp56 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_40", align 8
1900 %tmp57 = bitcast %struct._class_t* %tmp55 to i8*
1901 %call58 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %tmp57, i8* %tmp56)
1902 %tmp59 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_42", align 8
1903 %call6110 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %call548, i8* %tmp59, i8* %call58)
1904 %tmp15 = call i8* @objc_retain(i8* %call6110) nounwind
1905 call void @objc_release(i8* %call137) nounwind
1906 %tmp64 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_46", align 8
1907 %call66 = call signext i8 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8 (i8*, i8*, %1*)*)(i8* %call6110, i8* %tmp64, %1* bitcast (%struct.NSConstantString* @_unnamed_cfstring_44 to %1*))
1908 %tobool67 = icmp eq i8 %call66, 0
1909 br i1 %tobool67, label %if.end74, label %if.then68
1910
1911if.then68: ; preds = %if.then44
1912 %tmp70 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_48", align 8
1913 %call7220 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %call6110, i8* %tmp70)
1914 %tmp16 = call i8* @objc_retain(i8* %call7220) nounwind
1915 call void @objc_release(i8* %call6110) nounwind
1916 br label %if.end74
1917
1918if.end74: ; preds = %if.then68, %if.then44
1919 %filename.0.in = phi i8* [ %call7220, %if.then68 ], [ %call6110, %if.then44 ]
1920 %filename.0 = bitcast i8* %filename.0.in to %1*
1921 %tmp17 = load i8** bitcast (%0* @"\01l_objc_msgSend_fixup_isEqual_" to i8**), align 16
1922 %tmp18 = bitcast i8* %tmp17 to i8 (i8*, %struct._message_ref_t*, i8*, ...)*
1923 %call78 = call signext i8 (i8*, %struct._message_ref_t*, i8*, ...)* %tmp18(i8* %call137, %struct._message_ref_t* bitcast (%0* @"\01l_objc_msgSend_fixup_isEqual_" to %struct._message_ref_t*), i8* %filename.0.in)
1924 %tobool79 = icmp eq i8 %call78, 0
1925 br i1 %tobool79, label %land.lhs.true80, label %if.then109
1926
1927land.lhs.true80: ; preds = %if.end74
1928 %tmp82 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_25", align 8
1929 %call84 = call signext i8 bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8 (i8*, i8*)*)(i8* %filename.0.in, i8* %tmp82)
1930 %tobool86 = icmp eq i8 %call84, 0
1931 br i1 %tobool86, label %if.then109, label %if.end106
1932
1933if.end106: ; preds = %land.lhs.true80
1934 %tmp88 = load %struct._class_t** @"\01L_OBJC_CLASSLIST_REFERENCES_$_26", align 8
1935 %tmp90 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_28", align 8
1936 %tmp91 = bitcast %struct._class_t* %tmp88 to i8*
1937 %call9218 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %tmp91, i8* %tmp90, i8* %filename.0.in)
1938 %tmp20 = bitcast i8* %call9218 to %5*
1939 %tmp21 = call i8* @objc_retain(i8* %call9218) nounwind
1940 %tmp22 = bitcast %5* %url.025 to i8*
1941 call void @objc_release(i8* %tmp22) nounwind
1942 %tmp94 = load %struct._class_t** @"\01L_OBJC_CLASSLIST_REFERENCES_$_29", align 8
1943 %tmp95 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_31", align 8
1944 %tmp96 = bitcast %struct._class_t* %tmp94 to i8*
1945 %call97 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %tmp96, i8* %tmp95)
1946 %tmp99 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_33", align 8
1947 %call10119 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %call97, i8* %tmp99, i8* %call9218, i32 signext 1, %4** %err)
1948 %phitmp = icmp eq i8* %call10119, null
1949 br i1 %phitmp, label %if.then109, label %end
1950
1951if.then109: ; preds = %if.end106, %land.lhs.true80, %if.end74
1952 %url.129 = phi %5* [ %tmp20, %if.end106 ], [ %url.025, %if.end74 ], [ %url.025, %land.lhs.true80 ]
1953 %tmp110 = load %4** %err, align 8
1954 %tobool111 = icmp eq %4* %tmp110, null
1955 br i1 %tobool111, label %if.then112, label %if.end125
1956
1957if.then112: ; preds = %if.then109
1958 %tmp113 = load %struct._class_t** @"\01L_OBJC_CLASSLIST_REFERENCES_$_50", align 8
1959 %tmp114 = load %1** @NSCocoaErrorDomain, align 8
1960 %tmp115 = load %struct._class_t** @"\01L_OBJC_CLASSLIST_REFERENCES_$_51", align 8
1961 %call117 = call %1* @truncatedString(%1* %filename.0, i64 1034)
1962 %tmp118 = load %1** @NSFilePathErrorKey, align 8
1963 %tmp119 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_53", align 8
1964 %tmp120 = bitcast %struct._class_t* %tmp115 to i8*
1965 %call12113 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %tmp120, i8* %tmp119, %1* %call117, %1* %tmp118, i8* null)
1966 %tmp122 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_55", align 8
1967 %tmp123 = bitcast %struct._class_t* %tmp113 to i8*
1968 %call12414 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %tmp123, i8* %tmp122, %1* %tmp114, i64 258, i8* %call12113)
1969 %tmp23 = call i8* @objc_retain(i8* %call12414) nounwind
1970 %tmp25 = call i8* @objc_autorelease(i8* %tmp23) nounwind
1971 %tmp28 = bitcast i8* %tmp25 to %4*
1972 store %4* %tmp28, %4** %err, align 8
1973 br label %if.end125
1974
1975if.end125: ; preds = %if.then112, %if.then109
1976 %tmp127 = phi %4* [ %tmp110, %if.then109 ], [ %tmp28, %if.then112 ]
1977 %tmp126 = load %struct._class_t** @"\01L_OBJC_CLASSLIST_REFERENCES_$_56", align 8
1978 %tmp128 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_58", align 8
1979 %tmp129 = bitcast %struct._class_t* %tmp126 to i8*
1980 %call13015 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %tmp129, i8* %tmp128, %4* %tmp127)
1981 %tmp131 = load i8** @"\01L_OBJC_SELECTOR_REFERENCES_60", align 8
1982 %call13317 = call i8* (i8*, i8*, ...)* @objc_msgSend(i8* %call13015, i8* %tmp131)
1983 br label %end
1984
1985end: ; preds = %if.end125, %if.end106, %if.end, %land.lhs.true, %entry
1986 %filename.2 = phi %1* [ %filename.0, %if.end106 ], [ %filename.0, %if.end125 ], [ %tmp, %land.lhs.true ], [ null, %entry ], [ %tmp, %if.end ]
1987 %origFilename.0 = phi %1* [ %tmp, %if.end106 ], [ %tmp, %if.end125 ], [ %tmp, %land.lhs.true ], [ null, %entry ], [ %tmp, %if.end ]
1988 %url.2 = phi %5* [ %tmp20, %if.end106 ], [ %url.129, %if.end125 ], [ null, %land.lhs.true ], [ null, %entry ], [ %tmp13, %if.end ]
1989 call void @objc_release(i8* %tmp9) nounwind, !clang.imprecise_release !0
1990 %tmp29 = bitcast %5* %url.2 to i8*
1991 call void @objc_release(i8* %tmp29) nounwind, !clang.imprecise_release !0
1992 %tmp30 = bitcast %1* %origFilename.0 to i8*
1993 call void @objc_release(i8* %tmp30) nounwind, !clang.imprecise_release !0
1994 %tmp31 = bitcast %1* %filename.2 to i8*
1995 call void @objc_release(i8* %tmp31) nounwind, !clang.imprecise_release !0
1996 call void @objc_release(i8* %tmp7) nounwind, !clang.imprecise_release !0
1997 ret void
1998}
1999
2000!0 = metadata !{}