[llvm] [InstCombine] Add missing patterns for scmp and ucmp (PR #149225)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sat Oct 18 10:08:54 PDT 2025
================
@@ -3849,6 +3853,45 @@ Instruction *InstCombinerImpl::foldSelectToCmp(SelectInst &SI) {
}
}
+ // Special cases with constants: x == C ? 0 : (x > C-1 ? 1 : -1)
+ if (Pred == ICmpInst::ICMP_EQ && match(TV, m_Zero())) {
+ Value *X;
+ const APInt *C;
+ if (match(LHS, m_Value(X)) && match(RHS, m_APInt(C))) {
+ CmpPredicate InnerPred;
+ Value *InnerLHS, *InnerRHS;
+ const APInt *InnerTV, *InnerFV;
+ if (match(FV, m_Select(
+ m_ICmp(InnerPred, m_Value(InnerLHS), m_Value(InnerRHS)),
+ m_APInt(InnerTV), m_APInt(InnerFV)))) {
+
+ // x == C ? 0 : (x > C-1 ? 1 : -1)
+ if (ICmpInst::isGT(InnerPred) && InnerTV->isOne() &&
+ InnerFV->isAllOnes()) {
+ IsSigned = ICmpInst::isSigned(InnerPred);
+ bool CanSubOne = IsSigned ? !C->isMinSignedValue() : !C->isMinValue();
+ if (CanSubOne) {
+ APInt Cminus1 = *C - 1;
+ if (InnerLHS == X && match(InnerRHS, m_SpecificInt(Cminus1)))
----------------
dtcxzyw wrote:
```suggestion
if (match(InnerRHS, m_SpecificInt(Cminus1)))
```
https://github.com/llvm/llvm-project/pull/149225
More information about the llvm-commits
mailing list