[llvm] [InstCombine] Handle switch-to-select remapping correctly (PR #213302)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 13 05:00:41 PDT 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp -- llvm/lib/Transforms/Utils/SimplifyCFG.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 4e9681062..ceeef19d3 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -5085,8 +5085,9 @@ bool SimplifyCFGOpt::simplifySwitchOnSelect(SwitchInst *SI,
CmpPredicate Pred;
Value *X;
ConstantInt *C;
- if (Select->hasOneUse() && match(Select->getCondition(),
- m_OneUse(m_c_ICmp(Pred, m_Value(X), m_ConstantInt(C)))) &&
+ if (Select->hasOneUse() &&
+ match(Select->getCondition(),
+ m_OneUse(m_c_ICmp(Pred, m_Value(X), m_ConstantInt(C)))) &&
ICmpInst::isEquality(Pred)) {
// Normalize to select(icmp eq X, C, K, X).
Value *TrueVal = Select->getTrueValue();
@@ -5108,7 +5109,8 @@ bool SimplifyCFGOpt::simplifySwitchOnSelect(SwitchInst *SI,
SI->addCase(C, DestFork);
else
CaseC->setSuccessor(DestFork);
- // Not a new edge (BB->DestFork exists via K), just adding the PHI entry.
+ // Not a new edge (BB->DestFork exists via K), just adding the PHI
+ // entry.
addPredecessorToBlock(DestFork, BB, BB);
if (!IsDefault) {
@@ -5116,9 +5118,9 @@ bool SimplifyCFGOpt::simplifySwitchOnSelect(SwitchInst *SI,
bool OldDestStillTargeted =
SI->getDefaultDest() == OldDest ||
any_of(SI->cases(), [&](const SwitchInst::CaseHandle &Case) {
- return Case.getCaseIndex() != CaseC->getCaseIndex() &&
- Case.getCaseSuccessor() == OldDest;
- });
+ return Case.getCaseIndex() != CaseC->getCaseIndex() &&
+ Case.getCaseSuccessor() == OldDest;
+ });
for (PHINode &PN : make_early_inc_range(OldDest->phis()))
PN.removeIncomingValue(BB);
if (DTU && !OldDestStillTargeted)
``````````
</details>
https://github.com/llvm/llvm-project/pull/213302
More information about the llvm-commits
mailing list