[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.
This commit is contained in:
Roman Lebedev 2021-01-05 17:04:44 +03:00
parent fc96cb2dad
commit d15d81ce15
No known key found for this signature in database
GPG Key ID: 083C3EBB4A1689E0
1 changed files with 2 additions and 1 deletions

View File

@ -1099,7 +1099,7 @@ bool SimplifyCFGOpt::FoldValueComparisonIntoPredecessors(Instruction *TI,
++NumFoldValueComparisonIntoPredecessors;
});
SmallVector<BasicBlock *, 16> Preds(predecessors(BB));
SmallSetVector<BasicBlock *, 16> 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<BasicBlock *, int /*Num*/> &NewSuccessor :
NewSuccessors) {
for (auto I : seq(0, NewSuccessor.second)) {