[llvm] [SimplifyCFG] Fix DomTree update in `simplifySwitchWhenUMin` (PR #212008)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 25 03:18:42 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Yingwei Zheng (dtcxzyw)
<details>
<summary>Changes</summary>
In the test `switch_remove_dead_cases`, both case 4 and case 5 jump into bb `%case_ret`. Thus, the edge will be removed twice, triggering an assertion failure. This patch uses `applyUpdatesPermissive` to avoid duplicate removals.
---
Full diff: https://github.com/llvm/llvm-project/pull/212008.diff
2 Files Affected:
- (modified) llvm/lib/Transforms/Utils/SimplifyCFG.cpp (+2-2)
- (modified) llvm/test/Transforms/SimplifyCFG/switch-umin.ll (+1-1)
``````````diff
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 14efc3c4f5c00..1de2d718a105a 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -7840,7 +7840,7 @@ static bool simplifySwitchWhenUMin(SwitchInst *SI, DomTreeUpdater *DTU) {
// is reachable.
if (!SI->defaultDestUnreachable() || Case == SI->case_default()) {
if (DTU)
- DTU->applyUpdates(Updates);
+ DTU->applyUpdatesPermissive(Updates);
return !Updates.empty();
}
@@ -7852,7 +7852,7 @@ static bool simplifySwitchWhenUMin(SwitchInst *SI, DomTreeUpdater *DTU) {
Updates.push_back({DominatorTree::Delete, BB, Unreachable});
if (DTU)
- DTU->applyUpdates(Updates);
+ DTU->applyUpdatesPermissive(Updates);
return true;
}
diff --git a/llvm/test/Transforms/SimplifyCFG/switch-umin.ll b/llvm/test/Transforms/SimplifyCFG/switch-umin.ll
index ff958e4d04147..a6962a3c5285d 100644
--- a/llvm/test/Transforms/SimplifyCFG/switch-umin.ll
+++ b/llvm/test/Transforms/SimplifyCFG/switch-umin.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
declare void @a()
declare void @b()
``````````
</details>
https://github.com/llvm/llvm-project/pull/212008
More information about the llvm-commits
mailing list