[llvm] 7243120 - [CaptureTracking] Simplify reachability check (NFCI)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sun May 16 07:14:45 PDT 2021


Author: Nikita Popov
Date: 2021-05-16T16:04:10+02:00
New Revision: 7243120198914441c97de04bb6fc9afcc5b80731

URL: https://github.com/llvm/llvm-project/commit/7243120198914441c97de04bb6fc9afcc5b80731
DIFF: https://github.com/llvm/llvm-project/commit/7243120198914441c97de04bb6fc9afcc5b80731.diff

LOG: [CaptureTracking] Simplify reachability check (NFCI)

This code was re-implementing the same-BB case of
isPotentiallyReachable(). Historically, this was done because
CaptureTracking used additional caching for local dominance
queries. Now that it is no longer needed, the code is effectively
the same as isPotentiallyReachable().

The only difference are extra checks for invoke/phis. These are
misleading checks related to dominance in the value availability
sense that are not relevant for control reachability. The invoke
check was correct but redundant in that invokes are always
terminators, so `I` could never come before the invoke. The phi
check is a matter of interpretation (should an earlier phi node be
considered reachable from a later phi node in the same block?)
but ultimately doesn't matter because phis don't capture anyway.

Added: 
    

Modified: 
    llvm/lib/Analysis/CaptureTracking.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Analysis/CaptureTracking.cpp b/llvm/lib/Analysis/CaptureTracking.cpp
index 25815fc57463..5fe4f9befc86 100644
--- a/llvm/lib/Analysis/CaptureTracking.cpp
+++ b/llvm/lib/Analysis/CaptureTracking.cpp
@@ -109,40 +109,11 @@ namespace {
       if (BeforeHere == I)
         return !IncludeI;
 
-      BasicBlock *BB = I->getParent();
       // We explore this usage only if the usage can reach "BeforeHere".
       // If use is not reachable from entry, there is no need to explore.
-      if (!DT->isReachableFromEntry(BB))
+      if (!DT->isReachableFromEntry(I->getParent()))
         return true;
 
-      // Compute the case where both instructions are inside the same basic
-      // block.
-      if (BB == BeforeHere->getParent()) {
-        // 'I' dominates 'BeforeHere' => not safe to prune.
-        //
-        // The value defined by an invoke dominates an instruction only
-        // if it dominates every instruction in UseBB. A PHI is dominated only
-        // if the instruction dominates every possible use in the UseBB. Since
-        // UseBB == BB, avoid pruning.
-        if (isa<InvokeInst>(BeforeHere) || isa<PHINode>(I))
-          return false;
-        if (!BeforeHere->comesBefore(I))
-          return false;
-
-        // 'BeforeHere' comes before 'I', it's safe to prune if we also
-        // guarantee that 'I' never reaches 'BeforeHere' through a back-edge or
-        // by its successors, i.e, prune if:
-        //
-        //  (1) BB is an entry block or have no successors.
-        //  (2) There's no path coming back through BB successors.
-        if (BB->isEntryBlock() || !BB->getTerminator()->getNumSuccessors())
-          return true;
-
-        SmallVector<BasicBlock*, 32> Worklist;
-        Worklist.append(succ_begin(BB), succ_end(BB));
-        return !isPotentiallyReachableFromMany(Worklist, BB, nullptr, DT);
-      }
-
       // Check whether there is a path from I to BeforeHere.
       return !isPotentiallyReachable(I, BeforeHere, nullptr, DT);
     }


        


More information about the llvm-commits mailing list