[NFCI][SimplifyCFG] Fold branch to common dest: don't check cost if no qualified...
authorRoman Lebedev <lebedev.ri@gmail.com>
Wed, 24 Mar 2021 16:01:39 +0000 (19:01 +0300)
committerRoman Lebedev <lebedev.ri@gmail.com>
Wed, 24 Mar 2021 16:01:47 +0000 (19:01 +0300)
llvm/lib/Transforms/Utils/SimplifyCFG.cpp

index 92a1611..255bc26 100644 (file)
@@ -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)