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

Dan Gohman gohman at apple.com
Wed May 9 16:08:33 PDT 2012


Author: djg
Date: Wed May  9 18:08:33 2012
New Revision: 156520

URL: http://llvm.org/viewvc/llvm-project?rev=156520&view=rev
Log:
Fix the objc_storeStrong recognizer to stop before walking off the
end of a basic block if there's no store.

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

Modified: llvm/trunk/lib/Transforms/Scalar/ObjCARC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/ObjCARC.cpp?rev=156520&r1=156519&r2=156520&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/ObjCARC.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/ObjCARC.cpp Wed May  9 18:08:33 2012
@@ -3902,12 +3902,15 @@
   if (Load->getParent() != BB) return;
 
   // Walk down to find the store and the release, which may be in either order.
-  BasicBlock::iterator I = Load;
+  BasicBlock::iterator I = Load, End = BB->end();
   ++I;
   AliasAnalysis::Location Loc = AA->getLocation(Load);
   StoreInst *Store = 0;
   bool SawRelease = false;
   for (; !Store || !SawRelease; ++I) {
+    if (I == End)
+      return;
+
     Instruction *Inst = I;
     if (Inst == Release) {
       SawRelease = true;

Modified: llvm/trunk/test/Transforms/ObjCARC/contract-storestrong.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/ObjCARC/contract-storestrong.ll?rev=156520&r1=156519&r2=156520&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/ObjCARC/contract-storestrong.ll (original)
+++ llvm/trunk/test/Transforms/ObjCARC/contract-storestrong.ll Wed May  9 18:08:33 2012
@@ -132,4 +132,38 @@
   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 !{}





More information about the llvm-commits mailing list