[llvm-commits] [llvm] r159157 - in /llvm/trunk: lib/Transforms/Scalar/ObjCARC.cpp test/Transforms/ObjCARC/contract-testcases.ll

Dan Gohman gohman at apple.com
Mon Jun 25 12:47:37 PDT 2012


Author: djg
Date: Mon Jun 25 14:47:37 2012
New Revision: 159157

URL: http://llvm.org/viewvc/llvm-project?rev=159157&view=rev
Log:
Fix the objc_autoreleasedReturnValue optimization code to locate
the call correctly even in the case where it is an invoke. This
fixes rdar://11714057.

Modified:
    llvm/trunk/lib/Transforms/Scalar/ObjCARC.cpp
    llvm/trunk/test/Transforms/ObjCARC/contract-testcases.ll

Modified: llvm/trunk/lib/Transforms/Scalar/ObjCARC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/ObjCARC.cpp?rev=159157&r1=159156&r2=159157&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/ObjCARC.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/ObjCARC.cpp Mon Jun 25 14:47:37 2012
@@ -4064,8 +4064,22 @@
       if (!RetainRVMarker)
         break;
       BasicBlock::iterator BBI = Inst;
-      --BBI;
-      while (isNoopInstruction(BBI)) --BBI;
+      BasicBlock *InstParent = Inst->getParent();
+
+      // Step up to see if the call immediately precedes the RetainRV call.
+      // If it's an invoke, we have to cross a block boundary. And we have
+      // to carefully dodge no-op instructions.
+      do {
+        if (&*BBI == InstParent->begin()) {
+          BasicBlock *Pred = InstParent->getSinglePredecessor();
+          if (!Pred)
+            goto decline_rv_optimization;
+          BBI = Pred->getTerminator();
+          break;
+        }
+        --BBI;
+      } while (isNoopInstruction(BBI));
+
       if (&*BBI == GetObjCArg(Inst)) {
         Changed = true;
         InlineAsm *IA =
@@ -4075,6 +4089,7 @@
                          /*Constraints=*/"", /*hasSideEffects=*/true);
         CallInst::Create(IA, "", Inst);
       }
+    decline_rv_optimization:
       break;
     }
     case IC_InitWeak: {

Modified: llvm/trunk/test/Transforms/ObjCARC/contract-testcases.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/ObjCARC/contract-testcases.ll?rev=159157&r1=159156&r2=159157&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/ObjCARC/contract-testcases.ll (original)
+++ llvm/trunk/test/Transforms/ObjCARC/contract-testcases.ll Mon Jun 25 14:47:37 2012
@@ -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 @@
 ; 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 @@
   %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"}





More information about the llvm-commits mailing list