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