diff options
Diffstat (limited to 'test/Transforms/ObjCARC')
-rw-r--r-- | test/Transforms/ObjCARC/basic.ll | 24 | ||||
-rw-r--r-- | test/Transforms/ObjCARC/contract-storestrong.ll | 110 | ||||
-rw-r--r-- | test/Transforms/ObjCARC/contract-testcases.ll | 35 | ||||
-rw-r--r-- | test/Transforms/ObjCARC/split-backedge.ll | 48 | ||||
-rw-r--r-- | test/Transforms/ObjCARC/weak-dce.ll | 46 |
5 files changed, 259 insertions, 4 deletions
diff --git a/test/Transforms/ObjCARC/basic.ll b/test/Transforms/ObjCARC/basic.ll index ba2f778..d9bb3f2 100644 --- a/test/Transforms/ObjCARC/basic.ll +++ b/test/Transforms/ObjCARC/basic.ll @@ -1871,6 +1871,30 @@ return: ; preds = %if.then, %entry ret i8* %retval } +; An objc_retain can serve as a may-use for a different pointer. +; rdar://11931823 + +; CHECK: define void @test66( +; CHECK: %tmp7 = tail call i8* @objc_retain(i8* %cond) nounwind +; CHECK: tail call void @objc_release(i8* %cond) nounwind +; CHECK: } +define void @test66(i8* %tmp5, i8* %bar, i1 %tobool, i1 %tobool1, i8* %call) { +entry: + br i1 %tobool, label %cond.true, label %cond.end + +cond.true: + br label %cond.end + +cond.end: ; preds = %cond.true, %entry + %cond = phi i8* [ %tmp5, %cond.true ], [ %call, %entry ] + %tmp7 = tail call i8* @objc_retain(i8* %cond) nounwind + tail call void @objc_release(i8* %call) nounwind + %tmp8 = select i1 %tobool1, i8* %cond, i8* %bar + %tmp9 = tail call i8* @objc_retain(i8* %tmp8) nounwind + tail call void @objc_release(i8* %cond) nounwind + ret void +} + declare void @bar(i32 ()*) ; A few real-world testcases. diff --git a/test/Transforms/ObjCARC/contract-storestrong.ll b/test/Transforms/ObjCARC/contract-storestrong.ll index 4ff0596..2922f81 100644 --- a/test/Transforms/ObjCARC/contract-storestrong.ll +++ b/test/Transforms/ObjCARC/contract-storestrong.ll @@ -4,6 +4,7 @@ target datalayout = "e-p:64:64:64" declare i8* @objc_retain(i8*) declare void @objc_release(i8*) +declare void @use_pointer(i8*) @x = external global i8* @@ -57,3 +58,112 @@ entry: tail call void @objc_release(i8* %tmp) nounwind ret void } + +; Don't do this if there's a use of the old pointer value between the store +; and the release. + +; CHECK: define void @test3(i8* %newValue) { +; CHECK-NEXT: entry: +; CHECK-NEXT: %x0 = tail call i8* @objc_retain(i8* %newValue) nounwind +; CHECK-NEXT: %x1 = load i8** @x, align 8 +; 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) nounwind, !clang.imprecise_release !0 +; CHECK-NEXT: ret void +; CHECK-NEXT: } +define void @test3(i8* %newValue) { +entry: + %x0 = tail call i8* @objc_retain(i8* %newValue) nounwind + %x1 = load i8** @x, align 8 + 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. + +; CHECK: define i1 @test4(i8* %newValue, i8* %foo) { +; CHECK-NEXT: entry: +; CHECK-NEXT: %x0 = tail call i8* @objc_retain(i8* %newValue) nounwind +; CHECK-NEXT: %x1 = load i8** @x, align 8 +; 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) nounwind, !clang.imprecise_release !0 +; CHECK-NEXT: ret i1 %t +; CHECK-NEXT: } +define i1 @test4(i8* %newValue, i8* %foo) { +entry: + %x0 = tail call i8* @objc_retain(i8* %newValue) nounwind + %x1 = load i8** @x, align 8 + 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. + +; CHECK: define i1 @test5(i8* %newValue, i8* %foo) { +; CHECK: %t = icmp eq i8* %x1, %foo +; CHECK: tail call void @objc_storeStrong(i8** @x, i8* %newValue) nounwind +define i1 @test5(i8* %newValue, i8* %foo) { +entry: + %x0 = tail call i8* @objc_retain(i8* %newValue) nounwind + %x1 = load i8** @x, align 8 + %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. + +; CHECK: define i1 @test6(i8* %newValue, i8* %foo) { +; CHECK: %t = icmp eq i8* %x1, %foo +; CHECK: tail call void @objc_storeStrong(i8** @x, i8* %newValue) nounwind +define i1 @test6(i8* %newValue, i8* %foo) { +entry: + %x0 = tail call i8* @objc_retain(i8* %newValue) nounwind + %x1 = load i8** @x, align 8 + 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 +} + +; Like test0, but there's no store, so don't form an objc_storeStrong. + +; CHECK: define void @test7( +; CHECK-NEXT: entry: +; CHECK-NEXT: %0 = tail call i8* @objc_retain(i8* %p) nounwind +; CHECK-NEXT: %tmp = load i8** @x, align 8 +; CHECK-NEXT: tail call void @objc_release(i8* %tmp) nounwind +; CHECK-NEXT: ret void +; CHECK-NEXT: } +define void @test7(i8* %p) { +entry: + %0 = tail call i8* @objc_retain(i8* %p) nounwind + %tmp = load i8** @x, align 8 + tail call void @objc_release(i8* %tmp) nounwind + ret void +} + +; Like test0, but there's no retain, so don't form an objc_storeStrong. + +; CHECK: define void @test8( +; CHECK-NEXT: entry: +; CHECK-NEXT: %tmp = load i8** @x, align 8 +; CHECK-NEXT: store i8* %p, i8** @x, align 8 +; CHECK-NEXT: tail call void @objc_release(i8* %tmp) nounwind +; CHECK-NEXT: ret void +; CHECK-NEXT: } +define void @test8(i8* %p) { +entry: + %tmp = load i8** @x, align 8 + store i8* %p, i8** @x, align 8 + tail call void @objc_release(i8* %tmp) nounwind + ret void +} + +!0 = metadata !{} diff --git a/test/Transforms/ObjCARC/contract-testcases.ll b/test/Transforms/ObjCARC/contract-testcases.ll index 69fa837..1510ed0 100644 --- a/test/Transforms/ObjCARC/contract-testcases.ll +++ b/test/Transforms/ObjCARC/contract-testcases.ll @@ -4,17 +4,17 @@ %0 = type opaque %1 = type opaque %2 = type { i64, i64 } -%3 = type { i8*, i8* } %4 = type opaque declare %0* @"\01-[NSAttributedString(Terminal) pathAtIndex:effectiveRange:]"(%1*, i8* nocapture, i64, %2*) optsize declare i8* @objc_retainAutoreleasedReturnValue(i8*) -declare i8* @objc_msgSend_fixup(i8*, %3*, ...) +declare i8* @objc_msgSend_fixup(i8*, i8*, ...) +declare i8* @objc_msgSend(i8*, i8*, ...) declare void @objc_release(i8*) declare %2 @NSUnionRange(i64, i64, i64, i64) optsize declare i8* @objc_autoreleaseReturnValue(i8*) declare i8* @objc_autorelease(i8*) -declare i8* @objc_msgSend() nonlazybind +declare i32 @__gxx_personality_sj0(...) ; Don't get in trouble on bugpointed code. @@ -52,7 +52,7 @@ bb6: ; preds = %bb5, %bb4, %bb4, %b ; CHECK: %tmp8 = phi %0* [ %0, %bb ], [ %0, %bb ] define void @test1() { bb: - %tmp = tail call %0* bitcast (i8* ()* @objc_msgSend to %0* ()*)() + %tmp = tail call %0* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to %0* ()*)() %tmp2 = bitcast %0* %tmp to i8* %tmp3 = tail call i8* @objc_retainAutoreleasedReturnValue(i8* %tmp2) nounwind br i1 undef, label %bb7, label %bb7 @@ -61,3 +61,30 @@ bb7: ; preds = %bb6, %bb6, %bb5 %tmp8 = phi %0* [ %tmp, %bb ], [ %tmp, %bb ] unreachable } + +; When looking for the defining instruction for an objc_retainAutoreleasedReturnValue +; call, handle the case where it's an invoke in a different basic block. +; rdar://11714057 + +; CHECK: define void @_Z6doTestP8NSString() { +; CHECK: invoke.cont: ; preds = %entry +; CHECK-NEXT: call void asm sideeffect "mov\09r7, r7\09\09@ marker for objc_retainAutoreleaseReturnValue", ""() +; CHECK-NEXT: %tmp = tail call i8* @objc_retainAutoreleasedReturnValue(i8* %call) nounwind +define void @_Z6doTestP8NSString() { +entry: + %call = invoke i8* bitcast (i8* (i8*, i8*, ...)* @objc_msgSend to i8* ()*)() + to label %invoke.cont unwind label %lpad + +invoke.cont: ; preds = %entry + %tmp = tail call i8* @objc_retainAutoreleasedReturnValue(i8* %call) nounwind + unreachable + +lpad: ; preds = %entry + %tmp1 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__gxx_personality_sj0 to i8*) + cleanup + resume { i8*, i32 } undef +} + +!clang.arc.retainAutoreleasedReturnValueMarker = !{!0} + +!0 = metadata !{metadata !"mov\09r7, r7\09\09@ marker for objc_retainAutoreleaseReturnValue"} diff --git a/test/Transforms/ObjCARC/split-backedge.ll b/test/Transforms/ObjCARC/split-backedge.ll new file mode 100644 index 0000000..08e2dce --- /dev/null +++ b/test/Transforms/ObjCARC/split-backedge.ll @@ -0,0 +1,48 @@ +; RUN: opt -S -objc-arc < %s | FileCheck %s + +; Handle a retain+release pair entirely contained within a split loop backedge. +; rdar://11256239 + +; CHECK: define void @test0 +; CHECK: call i8* @objc_retain(i8* %call) nounwind +; CHECK: call i8* @objc_retain(i8* %call) nounwind +; CHECK: call i8* @objc_retain(i8* %cond) nounwind +; CHECK: call void @objc_release(i8* %call) nounwind +; CHECK: call void @objc_release(i8* %call) nounwind +; CHECK: call void @objc_release(i8* %cond) nounwind +define void @test0() { +entry: + br label %while.body + +while.body: ; preds = %while.cond + %call = invoke i8* @returner() + to label %invoke.cont unwind label %lpad, !clang.arc.no_objc_arc_exceptions !0 + +invoke.cont: ; preds = %while.body + %t0 = call i8* @objc_retain(i8* %call) nounwind + %t1 = call i8* @objc_retain(i8* %call) nounwind + %call.i1 = invoke i8* @returner() + to label %invoke.cont1 unwind label %lpad + +invoke.cont1: ; preds = %invoke.cont + %cond = select i1 undef, i8* null, i8* %call + %t2 = call i8* @objc_retain(i8* %cond) nounwind + call void @objc_release(i8* %call) nounwind + call void @objc_release(i8* %call) nounwind + call void @use_pointer(i8* %cond) + call void @objc_release(i8* %cond) nounwind + br label %while.body + +lpad: ; preds = %invoke.cont, %while.body + %t4 = landingpad { i8*, i32 } personality i8* bitcast (i32 (...)* @__objc_personality_v0 to i8*) + catch i8* null + ret void +} + +declare i8* @returner() +declare i32 @__objc_personality_v0(...) +declare void @objc_release(i8*) +declare i8* @objc_retain(i8*) +declare void @use_pointer(i8*) + +!0 = metadata !{} diff --git a/test/Transforms/ObjCARC/weak-dce.ll b/test/Transforms/ObjCARC/weak-dce.ll new file mode 100644 index 0000000..f094671 --- /dev/null +++ b/test/Transforms/ObjCARC/weak-dce.ll @@ -0,0 +1,46 @@ +; RUN: opt -S -basicaa -objc-arc < %s | FileCheck %s +; rdar://11434915 + +; Delete the weak calls and replace them with just the net retain. + +; CHECK: define void @test0(i8* %p) { +; CHECK-NEXT: call i8* @objc_retain(i8* %p) +; CHECK-NEXT: ret void + +define void @test0(i8* %p) { + %weakBlock = alloca i8*, align 8 + %tmp7 = call i8* @objc_initWeak(i8** %weakBlock, i8* %p) nounwind + %tmp26 = call i8* @objc_loadWeakRetained(i8** %weakBlock) nounwind + call void @objc_destroyWeak(i8** %weakBlock) nounwind + ret void +} + +; CHECK: define i8* @test1(i8* %p) { +; CHECK-NEXT: call i8* @objc_retain(i8* %p) +; CHECK-NEXT: ret i8* %p + +define i8* @test1(i8* %p) { + %weakBlock = alloca i8*, align 8 + %tmp7 = call i8* @objc_initWeak(i8** %weakBlock, i8* %p) nounwind + %tmp26 = call i8* @objc_loadWeakRetained(i8** %weakBlock) nounwind + call void @objc_destroyWeak(i8** %weakBlock) nounwind + ret i8* %tmp26 +} + +; CHECK: define i8* @test2(i8* %p, i8* %q) { +; CHECK-NEXT: call i8* @objc_retain(i8* %q) +; CHECK-NEXT: ret i8* %q + +define i8* @test2(i8* %p, i8* %q) { + %weakBlock = alloca i8*, align 8 + %tmp7 = call i8* @objc_initWeak(i8** %weakBlock, i8* %p) nounwind + %tmp19 = call i8* @objc_storeWeak(i8** %weakBlock, i8* %q) nounwind + %tmp26 = call i8* @objc_loadWeakRetained(i8** %weakBlock) nounwind + call void @objc_destroyWeak(i8** %weakBlock) nounwind + ret i8* %tmp26 +} + +declare i8* @objc_initWeak(i8**, i8*) +declare void @objc_destroyWeak(i8**) +declare i8* @objc_loadWeakRetained(i8**) +declare i8* @objc_storeWeak(i8** %weakBlock, i8* %q) |