[llvm] [InstCombine] Fold shifts + selects with -1 to scmp(X, 0) (PR #164129)

via llvm-commits llvm-commits at lists.llvm.org
Sat Oct 18 14:45: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/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/InstCombineSelect.cpp b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index 71aa94045..11daaf005 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -4693,17 +4693,18 @@ Instruction *InstCombinerImpl::visitSelectInst(SelectInst &SI) {
   // select (icmp sgt X, 0), 1, ashr X, bitwidth-1 -> scmp(X, 0)
   if (match(&SI, m_Select(m_ICmp(Pred, m_Value(CmpLHS), m_Value(CmpRHS)),
                           m_Value(TrueVal), m_Value(FalseVal))) &&
-      ((Pred == ICmpInst::ICMP_SLT && match(CmpLHS, m_Value(X)) && match(CmpRHS, m_One()) &&
+      ((Pred == ICmpInst::ICMP_SLT && match(CmpLHS, m_Value(X)) &&
+        match(CmpRHS, m_One()) &&
         match(TrueVal, m_AShr(m_Deferred(X), m_SpecificInt(BitWidth - 1))) &&
         match(FalseVal, m_One())) ||
-       (Pred == ICmpInst::ICMP_SGT && match(CmpLHS, m_Value(X)) && match(CmpRHS, m_Zero()) &&
-        match(TrueVal, m_One()) &&
+       (Pred == ICmpInst::ICMP_SGT && match(CmpLHS, m_Value(X)) &&
+        match(CmpRHS, m_Zero()) && match(TrueVal, m_One()) &&
         match(FalseVal, m_AShr(m_Deferred(X), m_SpecificInt(BitWidth - 1)))))) {
 
     Function *Scmp = Intrinsic::getOrInsertDeclaration(
         SI.getModule(), Intrinsic::scmp, {SI.getType(), SI.getType()});
     return CallInst::Create(Scmp, {X, ConstantInt::get(SI.getType(), 0)});
   }
-  
+
   return nullptr;
 }

``````````

</details>


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


More information about the llvm-commits mailing list