[llvm] [PatternMatch] Remove obsolete Signum_match matcher (NFCI) (PR #207390)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 3 06:02:31 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: AZero13 (AZero13)

<details>
<summary>Changes</summary>

Now, we just look for scmp with 0 instead. The 

---
Full diff: https://github.com/llvm/llvm-project/pull/207390.diff


2 Files Affected:

- (modified) llvm/include/llvm/IR/PatternMatch.h (-40) 
- (modified) llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp (+4-10) 


``````````diff
diff --git a/llvm/include/llvm/IR/PatternMatch.h b/llvm/include/llvm/IR/PatternMatch.h
index 95f5a9c5bba80..9dd40c9e1beee 100644
--- a/llvm/include/llvm/IR/PatternMatch.h
+++ b/llvm/include/llvm/IR/PatternMatch.h
@@ -3162,46 +3162,6 @@ m_c_FMul(const LHS &L, const RHS &R) {
   return BinaryOp_match<LHS, RHS, Instruction::FMul, true>(L, R);
 }
 
-template <typename Opnd_t> struct Signum_match {
-  Opnd_t Val;
-  Signum_match(const Opnd_t &V) : Val(V) {}
-
-  template <typename OpTy> bool match(OpTy *V) const {
-    unsigned TypeSize = V->getType()->getScalarSizeInBits();
-    if (TypeSize == 0)
-      return false;
-
-    unsigned ShiftWidth = TypeSize - 1;
-    Value *Op;
-
-    // This is the representation of signum we match:
-    //
-    //  signum(x) == (x >> 63) | (-x >>u 63)
-    //
-    // An i1 value is its own signum, so it's correct to match
-    //
-    //  signum(x) == (x >> 0)  | (-x >>u 0)
-    //
-    // for i1 values.
-
-    auto LHS = m_AShr(m_Value(Op), m_SpecificInt(ShiftWidth));
-    auto RHS = m_LShr(m_Neg(m_Deferred(Op)), m_SpecificInt(ShiftWidth));
-    auto Signum = m_c_Or(LHS, RHS);
-
-    return Signum.match(V) && Val.match(Op);
-  }
-};
-
-/// Matches a signum pattern.
-///
-/// signum(x) =
-///      x >  0  ->  1
-///      x == 0  ->  0
-///      x <  0  -> -1
-template <typename Val_t> inline Signum_match<Val_t> m_Signum(const Val_t &V) {
-  return Signum_match<Val_t>(V);
-}
-
 template <int Ind, typename Opnd_t> struct ExtractValue_match {
   Opnd_t Val;
   ExtractValue_match(const Opnd_t &V) : Val(V) {}
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index e6deb548819e8..104ed2343ea57 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -1463,9 +1463,11 @@ Instruction *InstCombinerImpl::foldICmpTruncConstant(ICmpInst &Cmp,
   }
 
   if (C.isOne() && C.getBitWidth() > 1) {
-    // icmp slt trunc(signum(V)) 1 --> icmp slt V, 1
+    // icmp slt trunc(scmp(V, 0)) 1 --> icmp slt V, 1
     Value *V = nullptr;
-    if (Pred == ICmpInst::ICMP_SLT && match(X, m_Signum(m_Value(V))))
+    if (Pred == ICmpInst::ICMP_SLT &&
+        match(X, m_Intrinsic<Intrinsic::scmp>(m_Value(V), m_ZeroInt())) &&
+        !V->getType()->getScalarType()->isIntegerTy(1))
       return new ICmpInst(ICmpInst::ICMP_SLT, V,
                           ConstantInt::get(V->getType(), 1));
   }
@@ -2084,14 +2086,6 @@ Instruction *InstCombinerImpl::foldICmpOrConstant(ICmpInst &Cmp,
                                                   BinaryOperator *Or,
                                                   const APInt &C) {
   ICmpInst::Predicate Pred = Cmp.getPredicate();
-  if (C.isOne()) {
-    // icmp slt signum(V) 1 --> icmp slt V, 1
-    Value *V = nullptr;
-    if (Pred == ICmpInst::ICMP_SLT && match(Or, m_Signum(m_Value(V))))
-      return new ICmpInst(ICmpInst::ICMP_SLT, V,
-                          ConstantInt::get(V->getType(), 1));
-  }
-
   Value *OrOp0 = Or->getOperand(0), *OrOp1 = Or->getOperand(1);
 
   // (icmp eq/ne (or disjoint x, C0), C1)

``````````

</details>


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


More information about the llvm-commits mailing list