[llvm] fe36b83 - [NFCI][SimplifyCFG] Fold branch to common dest: don't check cost if no qualified preds

Roman Lebedev via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 24 09:04:14 PDT 2021


Author: Roman Lebedev
Date: 2021-03-24T19:01:47+03:00
New Revision: fe36b834db8f14c8428e3eba304b46e2c072f0e2

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

LOG: [NFCI][SimplifyCFG] Fold branch to common dest: don't check cost if no qualified preds

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 92a16119c767..255bc2621d85 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -3094,7 +3094,11 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI, DomTreeUpdater *DTU,
     Preds.emplace_back(PredBlock);
   }
 
-  const unsigned PredCount = Preds.size();
+  // If there aren't any predecessors into which we can fold,
+  // don't bother checking the cost.
+  if (Preds.empty())
+    return Changed;
+
   // Only allow this transformation if computing the condition doesn't involve
   // too many instructions and these involved instructions can be executed
   // unconditionally. We denote all involved instructions except the condition
@@ -3102,6 +3106,7 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI, DomTreeUpdater *DTU,
   // number of the bonus instructions we'll need to create when cloning into
   // each predecessor does not exceed a certain threshold.
   unsigned NumBonusInsts = 0;
+  const unsigned PredCount = Preds.size();
   for (Instruction &I : *BB) {
     // Don't check the branch condition comparison itself.
     if (&I == Cond)


        


More information about the llvm-commits mailing list