[clang] [llvm] [SimplifyCFG] Hoist common code for switch multi-case destinations (PR #165700)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 30 13:32:35 PDT 2025
================
@@ -1866,10 +1866,18 @@ bool SimplifyCFGOpt::hoistCommonCodeFromSuccessors(Instruction *TI,
// If either of the blocks has it's address taken, then we can't do this fold,
// because the code we'd hoist would no longer run when we jump into the block
// by it's address.
+ SmallVector<BasicBlock *, 4> UniqSuccessors;
+ UniqSuccessors.reserve(BB->getTerminator()->getNumSuccessors());
for (auto *Succ : successors(BB)) {
if (Succ->hasAddressTaken())
return false;
- if (Succ->getSinglePredecessor())
+ // Collect all unique successors, using vec instead of set to preserve
+ // order.
+ if (find(UniqSuccessors, Succ) == UniqSuccessors.end())
----------------
nikic wrote:
Use `SmallSetVector` to maintain order instead.
https://github.com/llvm/llvm-project/pull/165700
More information about the llvm-commits
mailing list