[llvm] [InstCombine] Fold binary operator into select, when one of the opera… (PR #166241)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 3 13:52:39 PST 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/InstCombine/InstCombineAndOrXor.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/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index e45cc7b0f..7f78c1349 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -370,13 +370,11 @@ static Instruction *foldBinOpIntoSelectWhenConditionIsOperand(Instruction &I) {
ConstantInt::get(Ty, SelLeft->getValue() ^ 1),
ConstantInt::get(Ty, SelRight->getValue() ^ 0));
case Instruction::Add:
- return SelectInst::Create(CommonInput,
- ConstantInt::get(Ty, SelLeft->getValue() + 1),
- SelRight);
+ return SelectInst::Create(
+ CommonInput, ConstantInt::get(Ty, SelLeft->getValue() + 1), SelRight);
case Instruction::Sub:
- return SelectInst::Create(CommonInput,
- ConstantInt::get(Ty, SelLeft->getValue() - 1),
- SelRight);
+ return SelectInst::Create(
+ CommonInput, ConstantInt::get(Ty, SelLeft->getValue() - 1), SelRight);
case Instruction::Mul:
return SelectInst::Create(CommonInput,
ConstantInt::get(Ty, SelLeft->getValue()),
@@ -2510,7 +2508,6 @@ Instruction *InstCombinerImpl::visitAnd(BinaryOperator &I) {
return SelectInst::Create(Cmp, ConstantInt::getNullValue(Ty), Y);
}
-
if (Instruction *Res = foldBinOpIntoSelectWhenConditionIsOperand(I))
return Res;
@@ -4167,7 +4164,6 @@ Instruction *InstCombinerImpl::visitOr(BinaryOperator &I) {
if (Instruction *Res = foldBinOpIntoSelectWhenConditionIsOperand(I))
return Res;
-
// If the operands have no common bits set:
// or (mul X, Y), X --> add (mul X, Y), X --> mul X, (Y + 1)
if (match(&I, m_c_DisjointOr(m_OneUse(m_Mul(m_Value(X), m_Value(Y))),
@@ -5271,7 +5267,6 @@ Instruction *InstCombinerImpl::visitXor(BinaryOperator &I) {
if (Instruction *Res = foldBinOpIntoSelectWhenConditionIsOperand(I))
return Res;
-
// Fold (X & M) ^ (Y & ~M) -> (X & M) | (Y & ~M)
// This it a special case in haveNoCommonBitsSet, but the computeKnownBits
// calls in there are unnecessary as SimplifyDemandedInstructionBits should
``````````
</details>
https://github.com/llvm/llvm-project/pull/166241
More information about the llvm-commits
mailing list