[llvm] [DFAJumpThreading] Unify equivalent states (PR #162447)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 10 00:46:17 PDT 2025
================
@@ -384,6 +384,22 @@ inline raw_ostream &operator<<(raw_ostream &OS, const PathType &Path) {
return OS;
}
+/// Helper to get the successor corresponding to a particular case value for
+/// a switch statement.
+static BasicBlock *getNextCaseSuccessor(SwitchInst *Switch,
+ const APInt &NextState) {
+ BasicBlock *NextCase = nullptr;
+ for (auto Case : Switch->cases()) {
+ if (Case.getCaseValue()->getValue() == NextState) {
+ NextCase = Case.getCaseSuccessor();
+ break;
+ }
+ }
+ if (!NextCase)
+ NextCase = Switch->getDefaultDest();
+ return NextCase;
+}
----------------
nikic wrote:
I realize you only moved this code, but it would probably make sense to compute the value => successor mapping once instead of scanning the whole switch each time.
https://github.com/llvm/llvm-project/pull/162447
More information about the llvm-commits
mailing list