Fix a bug caused by indiscriminantly asking for the dominators of a predecessor.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40595 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/Scalar/GVN.cpp b/lib/Transforms/Scalar/GVN.cpp
index 119a9e4..ab6c913 100644
--- a/lib/Transforms/Scalar/GVN.cpp
+++ b/lib/Transforms/Scalar/GVN.cpp
@@ -723,7 +723,8 @@
return V = GetValueForBlock(IDom->getBlock(), orig, Phis);
}
-
+ if (std::distance(pred_begin(BB), pred_end(BB)) == 1)
+ return V = GetValueForBlock(IDom->getBlock(), orig, Phis);
// Otherwise, the idom is the loop, so we need to insert a PHI node. Do so
// now, then get values to fill in the incoming values for the PHI.
@@ -731,10 +732,10 @@
BB->begin());
PN->reserveOperandSpace(std::distance(pred_begin(BB), pred_end(BB)));
V = PN;
-
+
// Fill in the incoming values for the block.
for (pred_iterator PI = pred_begin(BB), E = pred_end(BB); PI != E; ++PI)
- PN->addIncoming(GetValueForBlock(DT.getNode(*PI)->getBlock(), orig, Phis), *PI);
+ PN->addIncoming(GetValueForBlock(*PI, orig, Phis), *PI);
return PN;
}