[llvm] [InstCombine] Optimise the expression `(C && A) || (!C && B)` with `FoldOrOfLogicalAnds` (PR #178438)

via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 13 05:03:20 PST 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 h,cpp -- llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp llvm/lib/Transforms/InstCombine/InstCombineInternal.h llvm/lib/Transforms/InstCombine/InstCombineSelect.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 a598590b8..edddc304e 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -4058,7 +4058,7 @@ Instruction *InstCombinerImpl::FoldOrOfLogicalAnds(Value *Op0, Value *Op1) {
     }
     return SelectInst::Create(C, A, B);
   }
-  
+
   // (!C && A) || (C && B)
   // (A && !C) || (C && B)
   // (!C && A) || (B && C)
@@ -4070,8 +4070,8 @@ Instruction *InstCombinerImpl::FoldOrOfLogicalAnds(Value *Op0, Value *Op1) {
     auto *SelCond = dyn_cast<SelectInst>(Op0);
     auto *SelFVal = dyn_cast<SelectInst>(Op1);
     bool MayNeedFreeze = SelCond && SelFVal &&
-    match(SelCond->getTrueValue(),
-          m_Not(m_Specific(SelFVal->getTrueValue())));
+                         match(SelCond->getTrueValue(),
+                               m_Not(m_Specific(SelFVal->getTrueValue())));
     if (MayNeedFreeze)
       C = Builder.CreateFreeze(C);
     if (!ProfcheckDisableMetadataFixes) {
@@ -4090,7 +4090,7 @@ Instruction *InstCombinerImpl::FoldOrOfLogicalAnds(Value *Op0, Value *Op1) {
     }
     return SelectInst::Create(C, B, A);
   }
-  
+
   return nullptr;
 }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/178438


More information about the llvm-commits mailing list