[llvm-commits] [llvm] r98103 - in /llvm/trunk: lib/Analysis/ScalarEvolution.cpp test/Analysis/ScalarEvolution/unreachable-code.ll

Dan Gohman gohman at apple.com
Tue Mar 9 15:46:50 PST 2010


Author: djg
Date: Tue Mar  9 17:46:50 2010
New Revision: 98103

URL: http://llvm.org/viewvc/llvm-project?rev=98103&view=rev
Log:
Avoid analyzing instructions in blocks not reachable from the entry block.
They are lots of trouble, and they don't matter. This fixes PR6559.

Added:
    llvm/trunk/test/Analysis/ScalarEvolution/unreachable-code.ll
Modified:
    llvm/trunk/lib/Analysis/ScalarEvolution.cpp

Modified: llvm/trunk/lib/Analysis/ScalarEvolution.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ScalarEvolution.cpp?rev=98103&r1=98102&r2=98103&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/ScalarEvolution.cpp (original)
+++ llvm/trunk/lib/Analysis/ScalarEvolution.cpp Tue Mar  9 17:46:50 2010
@@ -3101,9 +3101,16 @@
     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);

Added: llvm/trunk/test/Analysis/ScalarEvolution/unreachable-code.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Analysis/ScalarEvolution/unreachable-code.ll?rev=98103&view=auto
==============================================================================
--- llvm/trunk/test/Analysis/ScalarEvolution/unreachable-code.ll (added)
+++ llvm/trunk/test/Analysis/ScalarEvolution/unreachable-code.ll Tue Mar  9 17:46:50 2010
@@ -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
+}





More information about the llvm-commits mailing list