[llvm] [SimplifyCFG] Simplify uncond br with icmp & select (PR #165580)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 29 08:25:52 PDT 2025
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 f21a32fdb..927d17cfc 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -5122,7 +5122,7 @@ bool SimplifyCFGOpt::tryToSimplifyUncondBranchWithICmpInIt(
/// case. This is called when we find an icmp instruction (a seteq/setne with a
/// constant) and its following select instruction as the only TWO instruction
/// in a block that ends with an uncond branch. We are looking for a very
-/// specific pattern that occurs when "
+/// specific pattern that occurs when "
/// if (A == 1) return C1;
/// if (A == 2) return C2;
/// if (A < 3) return C3;
@@ -5165,8 +5165,8 @@ bool SimplifyCFGOpt::tryToSimplifyUncondBranchWithICmpSelectInIt(
ICmpInst *ICI, SelectInst *Select, IRBuilder<> &Builder) {
BasicBlock *BB = ICI->getParent();
- // If the block has any PHIs in it or the icmp/select has multiple uses, it is too
- // complex.
+ // If the block has any PHIs in it or the icmp/select has multiple uses, it is
+ // too complex.
if (isa<PHINode>(BB->begin()) || !ICI->hasOneUse() || !Select->hasOneUse())
return false;
@@ -5176,13 +5176,14 @@ bool SimplifyCFGOpt::tryToSimplifyUncondBranchWithICmpSelectInIt(
BasicBlock *Pred = BB->getSinglePredecessor();
if (!Pred || !isa<SwitchInst>(Pred->getTerminator()))
return false;
-
+
Value *IcmpCond;
ConstantInt *NewCaseVal;
CmpPredicate Predicate;
// Match icmp X, C
- if (!match(ICI, m_ICmp(Predicate, m_Value(IcmpCond), m_ConstantInt(NewCaseVal))))
+ if (!match(ICI,
+ m_ICmp(Predicate, m_Value(IcmpCond), m_ConstantInt(NewCaseVal))))
return false;
Value *SelectCond, *SelectTrueVal, *SelectFalseVal;
@@ -5239,8 +5240,8 @@ bool SimplifyCFGOpt::tryToSimplifyUncondBranchWithICmpSelectInIt(
isa<PHINode>(++BasicBlock::iterator(PHIUse)))
return false;
- // If the icmp is a SETEQ, then the default dest gets SelectFalseVal, the new edge gets
- // SelectTrueVal in the PHI.
+ // If the icmp is a SETEQ, then the default dest gets SelectFalseVal, the new
+ // edge gets SelectTrueVal in the PHI.
Value *DefaultCst = SelectFalseVal;
Value *NewCst = SelectTrueVal;
``````````
</details>
https://github.com/llvm/llvm-project/pull/165580
More information about the llvm-commits
mailing list