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