Make DSE only scan blocks that are reachable from the entry
authorChris Lattner <sabre@nondot.org>
Thu, 11 Feb 2010 05:11:54 +0000 (05:11 +0000)
committerChris Lattner <sabre@nondot.org>
Thu, 11 Feb 2010 05:11:54 +0000 (05:11 +0000)
block.  Other blocks may have pointer cycles that will crash
basicaa and other alias analyses.  In any case, there is no
point wasting cycles optimizing dead blocks.  This fixes
rdar://7635088

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@95852 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/DeadStoreElimination.cpp
test/Transforms/DeadStoreElimination/crash.ll

index 320afa19d5fbc30c3728c7253206e7c15f09a6ee..09c01d314124e65ff3c7767db50d7f99eeb93ee9 100644 (file)
@@ -44,8 +44,14 @@ namespace {
 
     virtual bool runOnFunction(Function &F) {
       bool Changed = false;
+      
+      DominatorTree &DT = getAnalysis<DominatorTree>();
+      
       for (Function::iterator I = F.begin(), E = F.end(); I != E; ++I)
-        Changed |= runOnBasicBlock(*I);
+        // Only check non-dead blocks.  Dead blocks may have strange pointer
+        // cycles that will confuse alias analysis.
+        if (DT.isReachableFromEntry(I))
+          Changed |= runOnBasicBlock(*I);
       return Changed;
     }
     
index f89f8f5185c68c0866ada6a0c2b857339df3b61c..6d8ba71b2094d4665eb0852459ea9e250e3d89b3 100644 (file)
@@ -41,3 +41,17 @@ bb14:                                             ; preds = %bb4
 }
 
 declare void @llvm.memcpy.i64(i8* nocapture, i8* nocapture, i64, i32) nounwind
+
+
+; rdar://7635088
+define i32 @test3() {
+entry:
+  ret i32 0
+  
+dead:
+  %P2 = getelementptr i32 *%P2, i32 52
+  %Q2 = getelementptr i32 *%Q2, i32 52
+  store i32 4, i32* %P2
+  store i32 4, i32* %Q2
+  br label %dead
+}
\ No newline at end of file