[llvm] 3af8a11 - [LoopDeletion] Separate logic in breakBackedgeIfNotTaken using symboic max trip count [nfc]

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 1 13:30:57 PDT 2021


Author: Philip Reames
Date: 2021-09-01T13:30:46-07:00
New Revision: 3af8a11bc66b93dc3f63ce7192647a27189aeefc

URL: https://github.com/llvm/llvm-project/commit/3af8a11bc66b93dc3f63ce7192647a27189aeefc
DIFF: https://github.com/llvm/llvm-project/commit/3af8a11bc66b93dc3f63ce7192647a27189aeefc.diff

LOG: [LoopDeletion] Separate logic in breakBackedgeIfNotTaken using symboic max trip count [nfc]

As mentioned in D108833, the logic for figuring out if a backedge is dead was somewhat interwoven with the SCEV based logic and the symbolic eval logic. This is my attempt at making the code easier to follow.

Note that this is only NFC after the work done in 29fa37ec.  Thanks to Nikita for catching that case.

Differential Revision: https://reviews.llvm.org/D108848

Added: 
    

Modified: 
    llvm/lib/Transforms/Scalar/LoopDeletion.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Scalar/LoopDeletion.cpp b/llvm/lib/Transforms/Scalar/LoopDeletion.cpp
index dd1fa1d081f82..73f97f2b6e515 100644
--- a/llvm/lib/Transforms/Scalar/LoopDeletion.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopDeletion.cpp
@@ -393,19 +393,23 @@ breakBackedgeIfNotTaken(Loop *L, DominatorTree &DT, ScalarEvolution &SE,
   if (!L->getLoopLatch())
     return LoopDeletionResult::Unmodified;
 
-  auto *BTCMax = SE.getConstantMaxBackedgeTakenCount(L);
-  if (!BTCMax->isZero()) {
-    auto *BTC = SE.getBackedgeTakenCount(L);
-    if (!BTC->isZero()) {
-      if (!isa<SCEVCouldNotCompute>(BTC) && SE.isKnownNonZero(BTC))
-        return LoopDeletionResult::Unmodified;
-      if (!canProveExitOnFirstIteration(L, DT, LI))
-        return LoopDeletionResult::Unmodified;
-    }
+  auto *BTC = SE.getSymbolicMaxBackedgeTakenCount(L);
+  if (BTC->isZero()) {
+    // SCEV knows this backedge isn't taken!
+    breakLoopBackedge(L, DT, SE, LI, MSSA);
+    return LoopDeletionResult::Deleted;
   }
 
-  breakLoopBackedge(L, DT, SE, LI, MSSA);
-  return LoopDeletionResult::Deleted;
+  // If SCEV leaves open the possibility of a zero trip count, see if
+  // symbolically evaluating the first iteration lets us prove the backedge
+  // unreachable.
+  if (isa<SCEVCouldNotCompute>(BTC) || !SE.isKnownNonZero(BTC))
+    if (canProveExitOnFirstIteration(L, DT, LI)) {
+      breakLoopBackedge(L, DT, SE, LI, MSSA);
+      return LoopDeletionResult::Deleted;
+    }
+
+  return LoopDeletionResult::Unmodified;
 }
 
 /// Remove a loop if it is dead.


        


More information about the llvm-commits mailing list