[llvm] r261134 - [ObjCARC] Handle ARCInstKind::ClaimRV in OptimizeIndividualCalls.
Frederic Riss via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 17 10:51:27 PST 2016
Author: friss
Date: Wed Feb 17 12:51:27 2016
New Revision: 261134
URL: http://llvm.org/viewvc/llvm-project?rev=261134&view=rev
Log:
[ObjCARC] Handle ARCInstKind::ClaimRV in OptimizeIndividualCalls.
When support for objc_unsafeClaimAutoreleasedReturnValue has been added to the
ARC optimizer in r258970, one case was missed which would lead the optimizer
to execute an llvm_unreachable. In this case, just handle ClaimRV in the same
way we handle RetainRV.
Added:
llvm/trunk/test/Transforms/ObjCARC/unsafe-claim-rv.ll
Modified:
llvm/trunk/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
Modified: llvm/trunk/lib/Transforms/ObjCARC/ObjCARCOpts.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/ObjCARC/ObjCARCOpts.cpp?rev=261134&r1=261133&r2=261134&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/ObjCARC/ObjCARCOpts.cpp (original)
+++ llvm/trunk/lib/Transforms/ObjCARC/ObjCARCOpts.cpp Wed Feb 17 12:51:27 2016
@@ -889,6 +889,7 @@ void ObjCARCOpt::OptimizeIndividualCalls
Inst->getParent(), Inst,
DependingInstructions, Visited, PA);
break;
+ case ARCInstKind::ClaimRV:
case ARCInstKind::RetainRV:
case ARCInstKind::AutoreleaseRV:
// Don't move these; the RV optimization depends on the autoreleaseRV
Added: llvm/trunk/test/Transforms/ObjCARC/unsafe-claim-rv.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/ObjCARC/unsafe-claim-rv.ll?rev=261134&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/ObjCARC/unsafe-claim-rv.ll (added)
+++ llvm/trunk/test/Transforms/ObjCARC/unsafe-claim-rv.ll Wed Feb 17 12:51:27 2016
@@ -0,0 +1,47 @@
+; RUN: opt -objc-arc -S < %s | FileCheck %s
+
+; Generated by compiling:
+;
+; id baz(void *X) { return (__bridge_transfer id)X; }
+;
+; void foo(id X) {
+; void *Y = 0;
+; if (X)
+; Y = (__bridge_retained void *)X;
+; baz(Y);
+; }
+;
+; clang -x objective-c -mllvm -enable-objc-arc-opts=0 -fobjc-arc -S -emit-llvm test.m
+;
+; And then hand-reduced further.
+
+declare i8* @objc_autoreleaseReturnValue(i8*)
+declare i8* @objc_unsafeClaimAutoreleasedReturnValue(i8*)
+declare i8* @objc_retain(i8*)
+declare void @objc_release(i8*)
+
+define void @foo(i8* %X) {
+entry:
+ %0 = tail call i8* @objc_retain(i8* %X)
+ %tobool = icmp eq i8* %0, null
+ br i1 %tobool, label %if.end, label %if.then
+
+if.then: ; preds = %entry
+ %1 = tail call i8* @objc_retain(i8* nonnull %0)
+ br label %if.end
+
+if.end: ; preds = %if.then, %entry
+ %Y.0 = phi i8* [ %1, %if.then ], [ null, %entry ]
+ %2 = tail call i8* @objc_autoreleaseReturnValue(i8* %Y.0)
+ %3 = tail call i8* @objc_unsafeClaimAutoreleasedReturnValue(i8* %2)
+ tail call void @objc_release(i8* %0)
+ ret void
+}
+
+; CHECK: if.then
+; CHECK: tail call i8* @objc_retain
+; CHECK-NEXT: call i8* @objc_autorelease
+; CHECK: %Y.0 = phi
+; CHECK-NEXT: tail call i8* @objc_unsafeClaimAutoreleasedReturnValue(i8* %Y.0)
+; CHECK-NEXT: tail call void @objc_release
+
More information about the llvm-commits
mailing list