[llvm] r357734 - An unreachable block may have a route to a reachable block, don't fast-path return that it can't.

Nick Lewycky via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 4 16:09:40 PDT 2019


Author: nicholas
Date: Thu Apr  4 16:09:40 2019
New Revision: 357734

URL: http://llvm.org/viewvc/llvm-project?rev=357734&view=rev
Log:
An unreachable block may have a route to a reachable block, don't fast-path return that it can't.

A block reachable from the entry block can't have any route to a block that's not reachable from the entry block (if it did, that route would make it reachable from the entry block). That is the intended performance optimization for isPotentiallyReachable. For the case where we ask whether an unreachable from entry block has a route to a reachable from entry block, we can't conclude one way or the other. Fix a bug where we claimed there could be no such route.

The fix in rL357425 ironically reintroduced the very bug it was fixing but only when a DominatorTree is provided. This fixes the remaining bug.

Modified:
    llvm/trunk/lib/Analysis/CFG.cpp
    llvm/trunk/unittests/Analysis/CFGTest.cpp

Modified: llvm/trunk/lib/Analysis/CFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/CFG.cpp?rev=357734&r1=357733&r2=357734&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/CFG.cpp (original)
+++ llvm/trunk/lib/Analysis/CFG.cpp Thu Apr  4 16:09:40 2019
@@ -254,8 +254,8 @@ bool llvm::isPotentiallyReachable(
   }
 
   if (DT) {
-    if (DT->isReachableFromEntry(A->getParent()) !=
-        DT->isReachableFromEntry(B->getParent()))
+    if (DT->isReachableFromEntry(A->getParent()) &&
+        !DT->isReachableFromEntry(B->getParent()))
       return false;
     if (!ExclusionSet || ExclusionSet->empty()) {
       if (A->getParent() == &A->getParent()->getParent()->getEntryBlock() &&

Modified: llvm/trunk/unittests/Analysis/CFGTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Analysis/CFGTest.cpp?rev=357734&r1=357733&r2=357734&view=diff
==============================================================================
--- llvm/trunk/unittests/Analysis/CFGTest.cpp (original)
+++ llvm/trunk/unittests/Analysis/CFGTest.cpp Thu Apr  4 16:09:40 2019
@@ -491,3 +491,17 @@ TEST_F(IsPotentiallyReachableTest, Diamo
                 "}");
   ExpectPath(true);
 }
+
+TEST_F(IsPotentiallyReachableTest, UnreachableToReachable) {
+  ParseAssembly("define void @test() {\n"
+                "entry:\n"
+                "  br label %exit\n"
+                "unreachableblock:\n"
+                "  %A = bitcast i8 undef to i8\n"
+                "  br label %exit\n"
+                "exit:\n"
+                "  %B = bitcast i8 undef to i8\n"
+                "  ret void\n"
+                "}");
+  ExpectPath(true);
+}




More information about the llvm-commits mailing list