Fix regression from r151466: an we can't replace uses of an instruction reachable...
authorEli Friedman <eli.friedman@gmail.com>
Tue, 13 Mar 2012 01:06:07 +0000 (01:06 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Tue, 13 Mar 2012 01:06:07 +0000 (01:06 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@152595 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/InstructionSimplify.cpp
test/Transforms/EarlyCSE/instsimplify-dom.ll [new file with mode: 0644]

index dd8b2634da69bb2a7d8a18db81bb8c7794d3cf11..44f870c81795e5831590511378127d1c732bbaa7 100644 (file)
@@ -94,9 +94,13 @@ static bool ValueDominatesPHI(Value *V, PHINode *P, const DominatorTree *DT) {
     return true;
 
   // If we have a DominatorTree then do a precise test.
-  if (DT)
-    return !DT->isReachableFromEntry(P->getParent()) ||
-      !DT->isReachableFromEntry(I->getParent()) || DT->dominates(I, P);
+  if (DT) {
+    if (!DT->isReachableFromEntry(P->getParent()))
+      return true;
+    if (!DT->isReachableFromEntry(I->getParent()))
+      return false;
+    return DT->dominates(I, P);
+  }
 
   // Otherwise, if the instruction is in the entry block, and is not an invoke,
   // then it obviously dominates all phi nodes.
diff --git a/test/Transforms/EarlyCSE/instsimplify-dom.ll b/test/Transforms/EarlyCSE/instsimplify-dom.ll
new file mode 100644 (file)
index 0000000..36dffec
--- /dev/null
@@ -0,0 +1,19 @@
+; RUN: opt -early-cse -S < %s | FileCheck %s
+; PR12231
+
+declare i32 @f()
+
+define i32 @fn() {
+entry:
+  br label %lbl_1215
+
+lbl_1215:
+  %ins34 = phi i32 [ %ins35, %xxx ], [ undef, %entry ]
+  ret i32 %ins34
+
+xxx:
+  %ins35 = call i32 @f()
+  br label %lbl_1215
+}
+
+; CHECK: define i32 @fn