Make isLCSSA ignore uses in blocks not reachable from the entry block,
as LCSSA no longer transforms such uses.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98033 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/LoopInfo.cpp b/lib/Analysis/LoopInfo.cpp
index 453af5a..2139c29 100644
--- a/lib/Analysis/LoopInfo.cpp
+++ b/lib/Analysis/LoopInfo.cpp
@@ -264,6 +264,13 @@
 
 /// isLCSSAForm - Return true if the Loop is in LCSSA form
 bool Loop::isLCSSAForm() const {
+  // Collect all the reachable blocks in the function, for fast lookups.
+  SmallPtrSet<BasicBlock *, 32> ReachableBBs;
+  BasicBlock *EntryBB = getHeader()->getParent()->begin();
+  for (df_iterator<BasicBlock *> NI = df_begin(EntryBB),
+       NE = df_end(EntryBB); NI != NE; ++NI)
+    ReachableBBs.insert(*NI);
+
   // Sort the blocks vector so that we can use binary search to do quick
   // lookups.
   SmallPtrSet<BasicBlock *, 16> LoopBBs(block_begin(), block_end());
@@ -277,9 +284,13 @@
         if (PHINode *P = dyn_cast<PHINode>(*UI))
           UserBB = P->getIncomingBlock(UI);
 
-        // Check the current block, as a fast-path.  Most values are used in
-        // the same block they are defined in.
-        if (UserBB != BB && !LoopBBs.count(UserBB))
+        // Check the current block, as a fast-path, before checking whether
+        // the use is anywhere in the loop.  Most values are used in the same
+        // block they are defined in.  Also, blocks not reachable from the
+        // entry are special; uses in them don't need to go through PHIs.
+        if (UserBB != BB &&
+            !LoopBBs.count(UserBB) &&
+            ReachableBBs.count(UserBB))
           return false;
       }
   }