[PATCH] D113293: [SimplifyCFG] Add early bailout if Use is not in same BB.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 9 02:32:06 PST 2021


fhahn updated this revision to Diff 385750.
fhahn added a comment.

Updated to use `cast` instead of `dyn_cast`.

In D113293#3113417 <https://reviews.llvm.org/D113293#3113417>, @RKSimon wrote:

> SGTM - might an alternative to a test be to run it on https://llvm-compile-time-tracker.com ?

Done: http://llvm-compile-time-tracker.com/compare.php?from=e3bfb6a14646fd3b344c491a5f46aaebd43090a7&to=2ea682d8c75956531a894e38af397caf627b3882&stat=instructions

There are a few small but notable improvements:

NewPM-O3:

  ClamAV	71699M	71567M (-0.18%)

NewPM-ReleaseLTO-g:

  kimwitu++	85293M	85171M (-0.14%)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D113293/new/

https://reviews.llvm.org/D113293

Files:
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp


Index: llvm/lib/Transforms/Utils/SimplifyCFG.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -6527,19 +6527,22 @@
 
   if (C->isNullValue() || isa<UndefValue>(C)) {
     // Only look at the first use, avoid hurting compile time with long uselists
-    User *Use = *I->user_begin();
+    auto *Use = cast<Instruction>(*I->user_begin());
+    // Bail out if Use is not in the same BB as I or Use == I or Use comes
+    // before I in the block. The latter two can be the case if Use is a PHI
+    // node.
+    if (!Use || Use->getParent() != I->getParent() || Use == I ||
+        Use->comesBefore(I))
+      return false;
 
     // Now make sure that there are no instructions in between that can alter
     // control flow (eg. calls)
-    for (BasicBlock::iterator
-             i = ++BasicBlock::iterator(I),
-             UI = BasicBlock::iterator(dyn_cast<Instruction>(Use));
-         i != UI; ++i) {
-      if (i == I->getParent()->end())
-        return false;
-      if (!isGuaranteedToTransferExecutionToSuccessor(&*i))
-        return false;
-    }
+    auto InstrRange =
+        make_range(std::next(I->getIterator()), Use->getIterator());
+    if (any_of(InstrRange, [](Instruction &I) {
+          return !isGuaranteedToTransferExecutionToSuccessor(&I);
+        }))
+      return false;
 
     // Look through GEPs. A load from a GEP derived from NULL is still undefined
     if (GetElementPtrInst *GEP = dyn_cast<GetElementPtrInst>(Use))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D113293.385750.patch
Type: text/x-patch
Size: 1574 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211109/44980e91/attachment.bin>


More information about the llvm-commits mailing list