Avoid analyzing instructions in blocks not reachable from the entry block.
authorDan Gohman <gohman@apple.com>
Tue, 9 Mar 2010 23:46:50 +0000 (23:46 +0000)
committerDan Gohman <gohman@apple.com>
Tue, 9 Mar 2010 23:46:50 +0000 (23:46 +0000)
They are lots of trouble, and they don't matter. This fixes PR6559.

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

lib/Analysis/ScalarEvolution.cpp
test/Analysis/ScalarEvolution/unreachable-code.ll [new file with mode: 0644]

index b979f3328d4ca39a489a0f0b8918ea2cb97fb5f9..15f072dbeb7e87b0d3b2882a7db0c1846c815ea2 100644 (file)
@@ -3101,9 +3101,16 @@ const SCEV *ScalarEvolution::createSCEV(Value *V) {
     return getUnknown(V);
 
   unsigned Opcode = Instruction::UserOp1;
-  if (Instruction *I = dyn_cast<Instruction>(V))
+  if (Instruction *I = dyn_cast<Instruction>(V)) {
     Opcode = I->getOpcode();
-  else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
+
+    // Don't attempt to analyze instructions in blocks that aren't
+    // reachable. Such instructions don't matter, and they aren't required
+    // to obey basic rules for definitions dominating uses which this
+    // analysis depends on.
+    if (!DT->isReachableFromEntry(I->getParent()))
+      return getUnknown(V);
+  } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(V))
     Opcode = CE->getOpcode();
   else if (ConstantInt *CI = dyn_cast<ConstantInt>(V))
     return getConstant(CI);
diff --git a/test/Analysis/ScalarEvolution/unreachable-code.ll b/test/Analysis/ScalarEvolution/unreachable-code.ll
new file mode 100644 (file)
index 0000000..51d9398
--- /dev/null
@@ -0,0 +1,13 @@
+; RUN: opt < %s -analyze -scalar-evolution | FileCheck %s
+
+; CHECK: %t = add i64 %t, 1
+; CHECK: -->  %t
+
+define void @foo() {
+entry:
+  ret void
+
+dead:
+  %t = add i64 %t, 1
+  ret void
+}