]> granicus.if.org Git - llvm/commitdiff
An unreachable block may have a route to a reachable block, don't fast-path return...
authorNick Lewycky <nicholas@mxc.ca>
Thu, 4 Apr 2019 23:09:40 +0000 (23:09 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Thu, 4 Apr 2019 23:09:40 +0000 (23:09 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357734 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/CFG.cpp
unittests/Analysis/CFGTest.cpp

index 44191f094e2de502d01539553485fd57c73fb576..18b83d6838cc94d985115a828432d52e59c28947 100644 (file)
@@ -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() &&
index ff95d8430d55f100faec2aeda1822e9f237cd02d..107bd085e6face5ec7be025418501a51b3f5f5d3 100644 (file)
@@ -491,3 +491,17 @@ TEST_F(IsPotentiallyReachableTest, DiamondOneSideExcludedTest) {
                 "}");
   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);
+}