From: Nick Lewycky Date: Thu, 4 Apr 2019 23:09:40 +0000 (+0000) Subject: An unreachable block may have a route to a reachable block, don't fast-path return... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4ebcbff143d4c7e86348f5371176d9db1e93d0e9;p=llvm 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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357734 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Analysis/CFG.cpp b/lib/Analysis/CFG.cpp index 44191f094e2..18b83d6838c 100644 --- a/lib/Analysis/CFG.cpp +++ b/lib/Analysis/CFG.cpp @@ -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() && diff --git a/unittests/Analysis/CFGTest.cpp b/unittests/Analysis/CFGTest.cpp index ff95d8430d5..107bd085e6f 100644 --- a/unittests/Analysis/CFGTest.cpp +++ b/unittests/Analysis/CFGTest.cpp @@ -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); +}