[llvm] d15d81c - [SimplifyCFG] FoldValueComparisonIntoPredecessors(): deal with each predecessor only once
Roman Lebedev via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 5 14:53:15 PST 2021
Author: Roman Lebedev
Date: 2021-01-06T01:52:37+03:00
New Revision: d15d81ce15e086208f30d99ce2257a75401dc12c
URL: https://github.com/llvm/llvm-project/commit/d15d81ce15e086208f30d99ce2257a75401dc12c
DIFF: https://github.com/llvm/llvm-project/commit/d15d81ce15e086208f30d99ce2257a75401dc12c.diff
LOG: [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.
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 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<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)) {
More information about the llvm-commits
mailing list