[cfe-commits] r163431 - in /cfe/trunk: lib/CodeGen/CGCall.cpp test/CodeGenObjC/arc-arm.m

John McCall rjmccall at apple.com
Fri Sep 7 16:30:51 PDT 2012


Author: rjmccall
Date: Fri Sep  7 18:30:50 2012
New Revision: 163431

URL: http://llvm.org/viewvc/llvm-project?rev=163431&view=rev
Log:
In ARC, if we're emitting assembly markers for calls to
objc_retainAutoreleasedReturnValue, we need to also be killing
them during return peepholing.  Make sure we recognize an
intervening bitcast, but more importantly, assert if we can't
find the asm marker at all.  rdar://problem/12133032

Modified:
    cfe/trunk/lib/CodeGen/CGCall.cpp
    cfe/trunk/test/CodeGenObjC/arc-arm.m

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=163431&r1=163430&r2=163431&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Fri Sep  7 18:30:50 2012
@@ -1363,12 +1363,23 @@
                                           .objc_retainAutoreleasedReturnValue) {
     doRetainAutorelease = false;
 
-    // Look for an inline asm immediately preceding the call and kill it, too.
-    llvm::Instruction *prev = call->getPrevNode();
-    if (llvm::CallInst *asmCall = dyn_cast_or_null<llvm::CallInst>(prev))
-      if (asmCall->getCalledValue()
-            == CGF.CGM.getARCEntrypoints().retainAutoreleasedReturnValueMarker)
-        insnsToKill.push_back(prev);
+    // If we emitted an assembly marker for this call (and the
+    // ARCEntrypoints field should have been set if so), go looking
+    // for that call.  If we can't find it, we can't do this
+    // optimization.  But it should always be the immediately previous
+    // instruction, unless we needed bitcasts around the call.
+    if (CGF.CGM.getARCEntrypoints().retainAutoreleasedReturnValueMarker) {
+      llvm::Instruction *prev = call->getPrevNode();
+      assert(prev);
+      if (isa<llvm::BitCastInst>(prev)) {
+        prev = prev->getPrevNode();
+        assert(prev);
+      }
+      assert(isa<llvm::CallInst>(prev));
+      assert(cast<llvm::CallInst>(prev)->getCalledValue() ==
+               CGF.CGM.getARCEntrypoints().retainAutoreleasedReturnValueMarker);
+      insnsToKill.push_back(prev);
+    }
   } else {
     return 0;
   }

Modified: cfe/trunk/test/CodeGenObjC/arc-arm.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/arc-arm.m?rev=163431&r1=163430&r2=163431&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjC/arc-arm.m (original)
+++ cfe/trunk/test/CodeGenObjC/arc-arm.m Fri Sep  7 18:30:50 2012
@@ -18,3 +18,20 @@
   // CHECK-NEXT: ret void
   id x = test1_helper();
 }
+
+// rdar://problem/12133032
+ at class A;
+A *test2(void) {
+  extern A *test2_helper(void);
+  // CHECK:      [[T0:%.*]] = call arm_aapcscc [[A:%.*]]* @test2_helper()
+  // CHECK-NEXT: ret [[A]]* [[T0]]
+  return test2_helper();
+}
+
+id test3(void) {
+  extern A *test3_helper(void);
+  // CHECK:      [[T0:%.*]] = call arm_aapcscc [[A:%.*]]* @test3_helper()
+  // CHECK-NEXT: [[T1:%.*]] = bitcast [[A]]* [[T0]] to i8*
+  // CHECK-NEXT: ret i8* [[T1]]
+  return test3_helper();
+}





More information about the cfe-commits mailing list