[clang] [llvm] [SimplifyCFG] Hoist common code for switch multi-case destinations (PR #165700)

Kunqiu Chen via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 31 03:40:21 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())
----------------
Camsyn wrote:

Thanks for the clarification.

https://github.com/llvm/llvm-project/pull/165700


More information about the llvm-commits mailing list