[llvm] [SimplfiyCFG] Deduplicate edges in `hoistSuccIdenticalTerminatorToSwitchOrIf` (PR #212017)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 25 04:46:29 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Yingwei Zheng (dtcxzyw)
<details>
<summary>Changes</summary>
Fix domtree update by deduplicating edges to be inserted. Tested by the function `@<!-- -->dedup`.
---
Full diff: https://github.com/llvm/llvm-project/pull/212017.diff
2 Files Affected:
- (modified) llvm/lib/Transforms/Utils/SimplifyCFG.cpp (+3-1)
- (modified) llvm/test/Transforms/SimplifyCFG/switch-dedup.ll (+1-1)
``````````diff
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 14efc3c4f5c00..994b8f32d28b7 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -2178,9 +2178,11 @@ bool SimplifyCFGOpt::hoistSuccIdenticalTerminatorToSwitchOrIf(
SmallVector<DominatorTree::UpdateType, 4> Updates;
// Update any PHI nodes in our new successors.
+ SmallPtrSet<BasicBlock *, 8> VisitedSuccs;
for (BasicBlock *Succ : successors(BB1)) {
addPredecessorToBlock(Succ, TIParent, BB1);
- if (DTU)
+
+ if (DTU && VisitedSuccs.insert(Succ).second)
Updates.push_back({DominatorTree::Insert, TIParent, Succ});
}
diff --git a/llvm/test/Transforms/SimplifyCFG/switch-dedup.ll b/llvm/test/Transforms/SimplifyCFG/switch-dedup.ll
index 1a8115e3ca386..f770d76d29b11 100644
--- a/llvm/test/Transforms/SimplifyCFG/switch-dedup.ll
+++ b/llvm/test/Transforms/SimplifyCFG/switch-dedup.ll
@@ -1,5 +1,5 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 6
-; RUN: opt < %s -passes=simplifycfg -S | FileCheck %s
+; RUN: opt < %s -passes=simplifycfg -simplifycfg-require-and-preserve-domtree=1 -S | FileCheck %s
define i32 @nodedup(i1 %c, i16 %v) {
; CHECK-LABEL: define i32 @nodedup(
``````````
</details>
https://github.com/llvm/llvm-project/pull/212017
More information about the llvm-commits
mailing list