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

Nick Lewycky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 2 19:41:40 PDT 2019


nicholas created this revision.
nicholas added a reviewer: asbirlea.
nicholas added a project: LLVM.
Herald added a subscriber: hiraditya.

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. From 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.

Fixes bug introduced in r357425.


https://reviews.llvm.org/D60171

Files:
  llvm/lib/Analysis/CFG.cpp
  llvm/unittests/Analysis/CFGTest.cpp


Index: llvm/unittests/Analysis/CFGTest.cpp
===================================================================
--- llvm/unittests/Analysis/CFGTest.cpp
+++ llvm/unittests/Analysis/CFGTest.cpp
@@ -491,3 +491,17 @@
                 "}");
   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);
+}
Index: llvm/lib/Analysis/CFG.cpp
===================================================================
--- llvm/lib/Analysis/CFG.cpp
+++ llvm/lib/Analysis/CFG.cpp
@@ -254,8 +254,8 @@
   }
 
   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() &&


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60171.193414.patch
Type: text/x-patch
Size: 1277 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190403/55e4a95f/attachment.bin>


More information about the llvm-commits mailing list