2011-06-16 07:37:01 +08:00
|
|
|
; RUN: opt -objc-arc-contract -S < %s | FileCheck %s
|
|
|
|
|
|
|
|
target datalayout = "e-p:64:64:64"
|
|
|
|
|
|
|
|
declare i8* @objc_retain(i8*)
|
|
|
|
declare void @objc_release(i8*)
|
2012-05-09 07:34:08 +08:00
|
|
|
declare void @use_pointer(i8*)
|
2011-06-16 07:37:01 +08:00
|
|
|
|
|
|
|
@x = external global i8*
|
|
|
|
|
2013-07-14 09:50:49 +08:00
|
|
|
; CHECK-LABEL: define void @test0(
|
2011-06-16 07:37:01 +08:00
|
|
|
; CHECK: entry:
|
2013-02-22 17:09:42 +08:00
|
|
|
; CHECK-NEXT: tail call void @objc_storeStrong(i8** @x, i8* %p) [[NUW:#[0-9]+]]
|
2011-06-16 07:37:01 +08:00
|
|
|
; CHECK-NEXT: ret void
|
2013-04-27 13:25:54 +08:00
|
|
|
; CHECK-NEXT: }
|
2011-06-16 07:37:01 +08:00
|
|
|
define void @test0(i8* %p) {
|
|
|
|
entry:
|
|
|
|
%0 = tail call i8* @objc_retain(i8* %p) nounwind
|
2015-02-28 05:17:42 +08:00
|
|
|
%tmp = load i8*, i8** @x, align 8
|
2011-06-16 07:37:01 +08:00
|
|
|
store i8* %0, i8** @x, align 8
|
|
|
|
tail call void @objc_release(i8* %tmp) nounwind
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; Don't do this if the load is volatile.
|
|
|
|
|
2015-02-20 08:02:49 +08:00
|
|
|
; CHECK-LABEL: define void @test1(i8* %p) {
|
2011-06-16 07:37:01 +08:00
|
|
|
; CHECK-NEXT: entry:
|
2013-02-22 17:09:42 +08:00
|
|
|
; CHECK-NEXT: %0 = tail call i8* @objc_retain(i8* %p) [[NUW]]
|
2015-02-28 05:17:42 +08:00
|
|
|
; CHECK-NEXT: %tmp = load volatile i8*, i8** @x, align 8
|
2011-06-16 07:37:01 +08:00
|
|
|
; CHECK-NEXT: store i8* %0, i8** @x, align 8
|
2013-02-22 17:09:42 +08:00
|
|
|
; CHECK-NEXT: tail call void @objc_release(i8* %tmp) [[NUW]]
|
2011-06-16 07:37:01 +08:00
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
; CHECK-NEXT: }
|
|
|
|
define void @test1(i8* %p) {
|
|
|
|
entry:
|
|
|
|
%0 = tail call i8* @objc_retain(i8* %p) nounwind
|
2015-02-28 05:17:42 +08:00
|
|
|
%tmp = load volatile i8*, i8** @x, align 8
|
2011-06-16 07:37:01 +08:00
|
|
|
store i8* %0, i8** @x, align 8
|
|
|
|
tail call void @objc_release(i8* %tmp) nounwind
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; Don't do this if the store is volatile.
|
|
|
|
|
2015-02-20 08:02:49 +08:00
|
|
|
; CHECK-LABEL: define void @test2(i8* %p) {
|
2011-06-16 07:37:01 +08:00
|
|
|
; CHECK-NEXT: entry:
|
2013-02-22 17:09:42 +08:00
|
|
|
; CHECK-NEXT: %0 = tail call i8* @objc_retain(i8* %p) [[NUW]]
|
2015-02-28 05:17:42 +08:00
|
|
|
; CHECK-NEXT: %tmp = load i8*, i8** @x, align 8
|
2011-08-13 06:50:01 +08:00
|
|
|
; CHECK-NEXT: store volatile i8* %0, i8** @x, align 8
|
2013-02-22 17:09:42 +08:00
|
|
|
; CHECK-NEXT: tail call void @objc_release(i8* %tmp) [[NUW]]
|
2011-06-16 07:37:01 +08:00
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
; CHECK-NEXT: }
|
|
|
|
define void @test2(i8* %p) {
|
|
|
|
entry:
|
|
|
|
%0 = tail call i8* @objc_retain(i8* %p) nounwind
|
2015-02-28 05:17:42 +08:00
|
|
|
%tmp = load i8*, i8** @x, align 8
|
2011-11-27 14:54:59 +08:00
|
|
|
store volatile i8* %0, i8** @x, align 8
|
2011-06-16 07:37:01 +08:00
|
|
|
tail call void @objc_release(i8* %tmp) nounwind
|
|
|
|
ret void
|
|
|
|
}
|
2012-05-09 07:34:08 +08:00
|
|
|
|
2012-05-09 22:43:50 +08:00
|
|
|
; Don't do this if there's a use of the old pointer value between the store
|
2012-05-09 07:34:08 +08:00
|
|
|
; and the release.
|
|
|
|
|
2015-02-20 08:02:49 +08:00
|
|
|
; CHECK-LABEL: define void @test3(i8* %newValue) {
|
|
|
|
; CHECK-NEXT: entry:
|
|
|
|
; CHECK-NEXT: %x0 = tail call i8* @objc_retain(i8* %newValue) [[NUW]]
|
2015-02-28 05:17:42 +08:00
|
|
|
; CHECK-NEXT: %x1 = load i8*, i8** @x, align 8
|
2015-02-20 08:02:49 +08:00
|
|
|
; CHECK-NEXT: store i8* %x0, i8** @x, align 8
|
|
|
|
; CHECK-NEXT: tail call void @use_pointer(i8* %x1), !clang.arc.no_objc_arc_exceptions !0
|
|
|
|
; CHECK-NEXT: tail call void @objc_release(i8* %x1) [[NUW]], !clang.imprecise_release !0
|
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
; CHECK-NEXT: }
|
2012-05-09 07:34:08 +08:00
|
|
|
define void @test3(i8* %newValue) {
|
|
|
|
entry:
|
|
|
|
%x0 = tail call i8* @objc_retain(i8* %newValue) nounwind
|
2015-02-28 05:17:42 +08:00
|
|
|
%x1 = load i8*, i8** @x, align 8
|
2012-05-09 07:34:08 +08:00
|
|
|
store i8* %newValue, i8** @x, align 8
|
|
|
|
tail call void @use_pointer(i8* %x1), !clang.arc.no_objc_arc_exceptions !0
|
|
|
|
tail call void @objc_release(i8* %x1) nounwind, !clang.imprecise_release !0
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; Like test3, but with an icmp use instead of a call, for good measure.
|
|
|
|
|
2015-02-20 08:02:49 +08:00
|
|
|
; CHECK-LABEL: define i1 @test4(i8* %newValue, i8* %foo) {
|
|
|
|
; CHECK-NEXT: entry:
|
|
|
|
; CHECK-NEXT: %x0 = tail call i8* @objc_retain(i8* %newValue) [[NUW]]
|
2015-02-28 05:17:42 +08:00
|
|
|
; CHECK-NEXT: %x1 = load i8*, i8** @x, align 8
|
2015-02-20 08:02:49 +08:00
|
|
|
; CHECK-NEXT: store i8* %x0, i8** @x, align 8
|
|
|
|
; CHECK-NEXT: %t = icmp eq i8* %x1, %foo
|
|
|
|
; CHECK-NEXT: tail call void @objc_release(i8* %x1) [[NUW]], !clang.imprecise_release !0
|
|
|
|
; CHECK-NEXT: ret i1 %t
|
|
|
|
; CHECK-NEXT: }
|
2012-05-09 07:34:08 +08:00
|
|
|
define i1 @test4(i8* %newValue, i8* %foo) {
|
|
|
|
entry:
|
|
|
|
%x0 = tail call i8* @objc_retain(i8* %newValue) nounwind
|
2015-02-28 05:17:42 +08:00
|
|
|
%x1 = load i8*, i8** @x, align 8
|
2012-05-09 07:34:08 +08:00
|
|
|
store i8* %newValue, i8** @x, align 8
|
|
|
|
%t = icmp eq i8* %x1, %foo
|
|
|
|
tail call void @objc_release(i8* %x1) nounwind, !clang.imprecise_release !0
|
|
|
|
ret i1 %t
|
|
|
|
}
|
|
|
|
|
|
|
|
; Do form an objc_storeStrong here, because the use is before the store.
|
|
|
|
|
2015-02-20 08:02:49 +08:00
|
|
|
; CHECK-LABEL: define i1 @test5(i8* %newValue, i8* %foo) {
|
2012-05-09 07:34:08 +08:00
|
|
|
; CHECK: %t = icmp eq i8* %x1, %foo
|
2013-02-22 17:09:42 +08:00
|
|
|
; CHECK: tail call void @objc_storeStrong(i8** @x, i8* %newValue) [[NUW]]
|
2013-04-27 13:25:54 +08:00
|
|
|
; CHECK: }
|
2012-05-09 07:34:08 +08:00
|
|
|
define i1 @test5(i8* %newValue, i8* %foo) {
|
|
|
|
entry:
|
|
|
|
%x0 = tail call i8* @objc_retain(i8* %newValue) nounwind
|
2015-02-28 05:17:42 +08:00
|
|
|
%x1 = load i8*, i8** @x, align 8
|
2012-05-09 07:34:08 +08:00
|
|
|
%t = icmp eq i8* %x1, %foo
|
|
|
|
store i8* %newValue, i8** @x, align 8
|
|
|
|
tail call void @objc_release(i8* %x1) nounwind, !clang.imprecise_release !0
|
|
|
|
ret i1 %t
|
|
|
|
}
|
|
|
|
|
|
|
|
; Like test5, but the release is before the store.
|
|
|
|
|
2015-02-20 08:02:49 +08:00
|
|
|
; CHECK-LABEL: define i1 @test6(i8* %newValue, i8* %foo) {
|
2012-05-09 07:34:08 +08:00
|
|
|
; CHECK: %t = icmp eq i8* %x1, %foo
|
2013-02-22 17:09:42 +08:00
|
|
|
; CHECK: tail call void @objc_storeStrong(i8** @x, i8* %newValue) [[NUW]]
|
2013-04-27 13:25:54 +08:00
|
|
|
; CHECK: }
|
2012-05-09 07:34:08 +08:00
|
|
|
define i1 @test6(i8* %newValue, i8* %foo) {
|
|
|
|
entry:
|
|
|
|
%x0 = tail call i8* @objc_retain(i8* %newValue) nounwind
|
2015-02-28 05:17:42 +08:00
|
|
|
%x1 = load i8*, i8** @x, align 8
|
2012-05-09 07:34:08 +08:00
|
|
|
tail call void @objc_release(i8* %x1) nounwind, !clang.imprecise_release !0
|
|
|
|
%t = icmp eq i8* %x1, %foo
|
|
|
|
store i8* %newValue, i8** @x, align 8
|
|
|
|
ret i1 %t
|
|
|
|
}
|
|
|
|
|
2012-05-10 07:08:33 +08:00
|
|
|
; Like test0, but there's no store, so don't form an objc_storeStrong.
|
|
|
|
|
2015-02-20 08:02:49 +08:00
|
|
|
; CHECK-LABEL: define void @test7(
|
2012-05-10 07:08:33 +08:00
|
|
|
; CHECK-NEXT: entry:
|
2013-02-22 17:09:42 +08:00
|
|
|
; CHECK-NEXT: %0 = tail call i8* @objc_retain(i8* %p) [[NUW]]
|
2015-02-28 05:17:42 +08:00
|
|
|
; CHECK-NEXT: %tmp = load i8*, i8** @x, align 8
|
2013-02-22 17:09:42 +08:00
|
|
|
; CHECK-NEXT: tail call void @objc_release(i8* %tmp) [[NUW]]
|
2012-05-10 07:08:33 +08:00
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
; CHECK-NEXT: }
|
|
|
|
define void @test7(i8* %p) {
|
|
|
|
entry:
|
|
|
|
%0 = tail call i8* @objc_retain(i8* %p) nounwind
|
2015-02-28 05:17:42 +08:00
|
|
|
%tmp = load i8*, i8** @x, align 8
|
2012-05-10 07:08:33 +08:00
|
|
|
tail call void @objc_release(i8* %tmp) nounwind
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
|
|
|
; Like test0, but there's no retain, so don't form an objc_storeStrong.
|
|
|
|
|
2015-02-20 08:02:49 +08:00
|
|
|
; CHECK-LABEL: define void @test8(
|
2012-05-10 07:08:33 +08:00
|
|
|
; CHECK-NEXT: entry:
|
2015-02-28 05:17:42 +08:00
|
|
|
; CHECK-NEXT: %tmp = load i8*, i8** @x, align 8
|
2012-05-10 07:08:33 +08:00
|
|
|
; CHECK-NEXT: store i8* %p, i8** @x, align 8
|
2013-02-22 17:09:42 +08:00
|
|
|
; CHECK-NEXT: tail call void @objc_release(i8* %tmp) [[NUW]]
|
2012-05-10 07:08:33 +08:00
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
; CHECK-NEXT: }
|
|
|
|
define void @test8(i8* %p) {
|
|
|
|
entry:
|
2015-02-28 05:17:42 +08:00
|
|
|
%tmp = load i8*, i8** @x, align 8
|
2012-05-10 07:08:33 +08:00
|
|
|
store i8* %p, i8** @x, align 8
|
|
|
|
tail call void @objc_release(i8* %tmp) nounwind
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2015-02-20 08:02:49 +08:00
|
|
|
; Make sure that we properly handle release that *may* release our new
|
|
|
|
; value in between the retain and the store. We need to be sure that
|
|
|
|
; this we can safely move the retain to the store. This specific test
|
|
|
|
; makes sure that we properly handled a release of an unrelated
|
|
|
|
; pointer.
|
|
|
|
;
|
|
|
|
; CHECK-LABEL: define i1 @test9(i8* %newValue, i8* %foo, i8* %unrelated_ptr) {
|
|
|
|
; CHECK-NOT: objc_storeStrong
|
|
|
|
define i1 @test9(i8* %newValue, i8* %foo, i8* %unrelated_ptr) {
|
|
|
|
entry:
|
|
|
|
%x0 = tail call i8* @objc_retain(i8* %newValue) nounwind
|
|
|
|
tail call void @objc_release(i8* %unrelated_ptr) nounwind, !clang.imprecise_release !0
|
2015-02-28 05:17:42 +08:00
|
|
|
%x1 = load i8*, i8** @x, align 8
|
2015-02-20 08:02:49 +08:00
|
|
|
tail call void @objc_release(i8* %x1) nounwind, !clang.imprecise_release !0
|
|
|
|
%t = icmp eq i8* %x1, %foo
|
|
|
|
store i8* %newValue, i8** @x, align 8
|
|
|
|
ret i1 %t
|
|
|
|
}
|
|
|
|
|
|
|
|
; Make sure that we don't perform the optimization when we just have a call.
|
|
|
|
;
|
|
|
|
; CHECK-LABEL: define i1 @test10(i8* %newValue, i8* %foo, i8* %unrelated_ptr) {
|
|
|
|
; CHECK-NOT: objc_storeStrong
|
|
|
|
define i1 @test10(i8* %newValue, i8* %foo, i8* %unrelated_ptr) {
|
|
|
|
entry:
|
|
|
|
%x0 = tail call i8* @objc_retain(i8* %newValue) nounwind
|
|
|
|
call void @use_pointer(i8* %unrelated_ptr)
|
2015-02-28 05:17:42 +08:00
|
|
|
%x1 = load i8*, i8** @x, align 8
|
2015-02-20 08:02:49 +08:00
|
|
|
tail call void @objc_release(i8* %x1) nounwind, !clang.imprecise_release !0
|
|
|
|
%t = icmp eq i8* %x1, %foo
|
|
|
|
store i8* %newValue, i8** @x, align 8
|
|
|
|
ret i1 %t
|
|
|
|
}
|
|
|
|
|
|
|
|
; Make sure we form the store strong if the use in between the retain
|
|
|
|
; and the store does not touch reference counts.
|
|
|
|
; CHECK-LABEL: define i1 @test11(i8* %newValue, i8* %foo, i8* %unrelated_ptr) {
|
|
|
|
; CHECK: objc_storeStrong
|
|
|
|
define i1 @test11(i8* %newValue, i8* %foo, i8* %unrelated_ptr) {
|
|
|
|
entry:
|
|
|
|
%x0 = tail call i8* @objc_retain(i8* %newValue) nounwind
|
|
|
|
%t = icmp eq i8* %newValue, %foo
|
2015-02-28 05:17:42 +08:00
|
|
|
%x1 = load i8*, i8** @x, align 8
|
2015-02-20 08:02:49 +08:00
|
|
|
tail call void @objc_release(i8* %x1) nounwind, !clang.imprecise_release !0
|
|
|
|
store i8* %newValue, i8** @x, align 8
|
|
|
|
ret i1 %t
|
|
|
|
}
|
|
|
|
|
2016-05-27 10:13:53 +08:00
|
|
|
; Make sure that we form the store strong even if there are bitcasts on
|
|
|
|
; the pointers.
|
|
|
|
; CHECK-LABEL: define void @test12(
|
|
|
|
; CHECK: entry:
|
|
|
|
; CHECK-NEXT: %p16 = bitcast i8** @x to i16**
|
|
|
|
; CHECK-NEXT: %tmp16 = load i16*, i16** %p16, align 8
|
|
|
|
; CHECK-NEXT: %tmp8 = bitcast i16* %tmp16 to i8*
|
|
|
|
; CHECK-NEXT: %p32 = bitcast i8** @x to i32**
|
|
|
|
; CHECK-NEXT: %v32 = bitcast i8* %p to i32*
|
|
|
|
; CHECK-NEXT: %0 = bitcast i16** %p16 to i8**
|
|
|
|
; CHECK-NEXT: tail call void @objc_storeStrong(i8** %0, i8* %p)
|
|
|
|
; CHECK-NEXT: ret void
|
|
|
|
; CHECK-NEXT: }
|
|
|
|
define void @test12(i8* %p) {
|
|
|
|
entry:
|
|
|
|
%retain = tail call i8* @objc_retain(i8* %p) nounwind
|
|
|
|
%p16 = bitcast i8** @x to i16**
|
|
|
|
%tmp16 = load i16*, i16** %p16, align 8
|
|
|
|
%tmp8 = bitcast i16* %tmp16 to i8*
|
|
|
|
%p32 = bitcast i8** @x to i32**
|
|
|
|
%v32 = bitcast i8* %retain to i32*
|
|
|
|
store i32* %v32, i32** %p32, align 8
|
|
|
|
tail call void @objc_release(i8* %tmp8) nounwind
|
|
|
|
ret void
|
|
|
|
}
|
|
|
|
|
2017-04-05 11:44:09 +08:00
|
|
|
; This used to crash.
|
|
|
|
; CHECK-LABEL: define i8* @test13(
|
|
|
|
; CHECK: tail call void @objc_storeStrong(i8** %{{.*}}, i8* %[[NEW:.*]])
|
|
|
|
; CHECK-NEXT: ret i8* %[[NEW]]
|
|
|
|
|
|
|
|
define i8* @test13(i8* %a0, i8* %a1, i8** %addr, i8* %new) {
|
|
|
|
%old = load i8*, i8** %addr, align 8
|
|
|
|
call void @objc_release(i8* %old)
|
|
|
|
%retained = call i8* @objc_retain(i8* %new)
|
|
|
|
store i8* %retained, i8** %addr, align 8
|
|
|
|
ret i8* %retained
|
|
|
|
}
|
|
|
|
|
IR: Make metadata typeless in assembly
Now that `Metadata` is typeless, reflect that in the assembly. These
are the matching assembly changes for the metadata/value split in
r223802.
- Only use the `metadata` type when referencing metadata from a call
intrinsic -- i.e., only when it's used as a `Value`.
- Stop pretending that `ValueAsMetadata` is wrapped in an `MDNode`
when referencing it from call intrinsics.
So, assembly like this:
define @foo(i32 %v) {
call void @llvm.foo(metadata !{i32 %v}, metadata !0)
call void @llvm.foo(metadata !{i32 7}, metadata !0)
call void @llvm.foo(metadata !1, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{metadata !3}, metadata !0)
ret void, !bar !2
}
!0 = metadata !{metadata !2}
!1 = metadata !{i32* @global}
!2 = metadata !{metadata !3}
!3 = metadata !{}
turns into this:
define @foo(i32 %v) {
call void @llvm.foo(metadata i32 %v, metadata !0)
call void @llvm.foo(metadata i32 7, metadata !0)
call void @llvm.foo(metadata i32* @global, metadata !0)
call void @llvm.foo(metadata !3, metadata !0)
call void @llvm.foo(metadata !{!3}, metadata !0)
ret void, !bar !2
}
!0 = !{!2}
!1 = !{i32* @global}
!2 = !{!3}
!3 = !{}
I wrote an upgrade script that handled almost all of the tests in llvm
and many of the tests in cfe (even handling many `CHECK` lines). I've
attached it (or will attach it in a moment if you're speedy) to PR21532
to help everyone update their out-of-tree testcases.
This is part of PR21532.
llvm-svn: 224257
2014-12-16 03:07:53 +08:00
|
|
|
!0 = !{}
|
2013-02-22 17:09:42 +08:00
|
|
|
|
|
|
|
; CHECK: attributes [[NUW]] = { nounwind }
|