aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/Local.cpp
diff options
context:
space:
mode:
authorOwen Anderson <resistor@mac.com>2023-01-01 18:17:19 -0700
committerOwen Anderson <resistor@mac.com>2023-01-04 16:47:13 -0700
commit733740b18936364f20d9858e3a6f08855ec66b8b (patch)
treec7c40a20b5721a1d0c9f8d372fa17c21952ad607 /llvm/lib/Transforms/Utils/Local.cpp
parentd65e66abb3bd4535e1900c0c7901c0f6254acf34 (diff)
downloadllvm-733740b18936364f20d9858e3a6f08855ec66b8b.zip
llvm-733740b18936364f20d9858e3a6f08855ec66b8b.tar.gz
llvm-733740b18936364f20d9858e3a6f08855ec66b8b.tar.bz2
Fix a phase-ordering problem in SimplifyCFG.
Switch simplification could sometimes fail to notice when an intermediate case removal caused the switch condition to become constant. This would cause the switch to be simplified into a conditional branch rather than a direct branch. Most of the time this didn't matter, except that occasionally downstream parts of SimplifyCFG expect tautological branches to already have been eliminated. The missed handling in switch simplification would cause an assertion failure in the downstream code. Triggering the assertion failure is fairly sensitive to the exact order of various simplifications. Fixes https://github.com/llvm/llvm-project/issues/59768 Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D140831
Diffstat (limited to 'llvm/lib/Transforms/Utils/Local.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/Local.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Utils/Local.cpp b/llvm/lib/Transforms/Utils/Local.cpp
index d21e351..0b3799c 100644
--- a/llvm/lib/Transforms/Utils/Local.cpp
+++ b/llvm/lib/Transforms/Utils/Local.cpp
@@ -237,6 +237,14 @@ bool llvm::ConstantFoldTerminator(BasicBlock *BB, bool DeleteDeadConditions,
DefaultDest->removePredecessor(ParentBB);
i = SI->removeCase(i);
e = SI->case_end();
+
+ // Removing this case may have made the condition constant. In that
+ // case, update CI and restart iteration through the cases.
+ if (auto *NewCI = dyn_cast<ConstantInt>(SI->getCondition())) {
+ CI = NewCI;
+ i = SI->case_begin();
+ }
+
Changed = true;
continue;
}