From d15d81ce15e086208f30d99ce2257a75401dc12c Mon Sep 17 00:00:00 2001 From: Roman Lebedev Date: Tue, 5 Jan 2021 17:04:44 +0300 Subject: [PATCH] [SimplifyCFG] FoldValueComparisonIntoPredecessors(): deal with each predecessor only once If the predecessor is a switch, and BB is not the default destination, multiple cases could have the same destination. and it doesn't make sense to re-process the predecessor, because we won't make any changes, once is enough. I'm not sure this can be really tested, other than via the assertion being added here, which fires without the fix. --- llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp index 08005c198298..6d5a68214e7c 100644 --- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp +++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp @@ -1099,7 +1099,7 @@ bool SimplifyCFGOpt::FoldValueComparisonIntoPredecessors(Instruction *TI, ++NumFoldValueComparisonIntoPredecessors; }); - SmallVector Preds(predecessors(BB)); + SmallSetVector Preds(pred_begin(BB), pred_end(BB)); while (!Preds.empty()) { BasicBlock *Pred = Preds.pop_back_val(); @@ -1260,6 +1260,7 @@ bool SimplifyCFGOpt::FoldValueComparisonIntoPredecessors(Instruction *TI, // Okay, at this point, we know which new successor Pred will get. Make // sure we update the number of entries in the PHI nodes for these // successors. + assert(!NewSuccessors.empty() && "Should be adding some new successors."); for (const std::pair &NewSuccessor : NewSuccessors) { for (auto I : seq(0, NewSuccessor.second)) {