Skip to content

Commit a6ed16c

Browse files
committed
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. llvm-svn: 357734
1 parent 875565e commit a6ed16c

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

llvm/lib/Analysis/CFG.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,8 @@ bool llvm::isPotentiallyReachable(
254254
}
255255

256256
if (DT) {
257-
if (DT->isReachableFromEntry(A->getParent()) !=
258-
DT->isReachableFromEntry(B->getParent()))
257+
if (DT->isReachableFromEntry(A->getParent()) &&
258+
!DT->isReachableFromEntry(B->getParent()))
259259
return false;
260260
if (!ExclusionSet || ExclusionSet->empty()) {
261261
if (A->getParent() == &A->getParent()->getParent()->getEntryBlock() &&

llvm/unittests/Analysis/CFGTest.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,3 +491,17 @@ TEST_F(IsPotentiallyReachableTest, DiamondOneSideExcludedTest) {
491491
"}");
492492
ExpectPath(true);
493493
}
494+
495+
TEST_F(IsPotentiallyReachableTest, UnreachableToReachable) {
496+
ParseAssembly("define void @test() {\n"
497+
"entry:\n"
498+
" br label %exit\n"
499+
"unreachableblock:\n"
500+
" %A = bitcast i8 undef to i8\n"
501+
" br label %exit\n"
502+
"exit:\n"
503+
" %B = bitcast i8 undef to i8\n"
504+
" ret void\n"
505+
"}");
506+
ExpectPath(true);
507+
}

0 commit comments

Comments
 (0)