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

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 31 02:06:23 PDT 2025


================
@@ -2156,9 +2164,13 @@ bool SimplifyCFGOpt::hoistSuccIdenticalTerminatorToSwitchOrIf(
       Updates.push_back({DominatorTree::Insert, TIParent, Succ});
   }
 
-  if (DTU)
-    for (BasicBlock *Succ : successors(TI))
+  if (DTU) {
+    // TI might be a switch with multi-cases destination, so we need to care for
+    // the duplication of successors.
+    SmallPtrSet<BasicBlock *, 4> UniqSuccs(llvm::from_range, successors(TI));
----------------
nikic wrote:

Ah, I didn't realize that this is a separate function. I do think adding the parameter is fine.

Note that you can't use SmallPtrSet here, because order for the updates matters.

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


More information about the llvm-commits mailing list