[llvm] [InstCombine][AArch64] Combine ANDs with two constant CMPHS (PR #213995)
Paul Walker via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 6 05:10:58 PDT 2026
================
@@ -3392,6 +3392,46 @@ static std::optional<Instruction *> instCombineSVEUMin(InstCombiner &IC,
return std::nullopt;
}
+static std::optional<Instruction *> instCombineSVEAnd(InstCombiner &IC,
+ IntrinsicInst &II) {
+ // and(cmphs(pg, C0, A), cmphs(pg, A, C1))
+ // ->
+ // cmphs(pg, C0 - C1, sub(pg, A, C1))
+ constexpr Intrinsic::ID CmphsID = Intrinsic::aarch64_sve_cmphs;
+ Value *Pg = II.getOperand(0);
+ Value *LHS = II.getOperand(1);
+ Value *RHS = II.getOperand(2);
+
+ Value *A, *PgLHS, *PgRHS;
+ uint64_t ConstA, ConstB;
+ if (!match(LHS, m_Intrinsic<CmphsID>(m_Value(PgLHS), m_ConstantInt(ConstA),
+ m_Value(A))) ||
+ !match(RHS, m_Intrinsic<CmphsID>(m_Value(PgRHS), m_Specific(A),
+ m_ConstantInt(ConstB))) ||
+ !LHS->hasOneUser() || !RHS->hasOneUser())
+ return std::nullopt;
+
+ // Always false regardless of predication
+ if (ConstB > ConstA)
+ return IC.replaceInstUsesWith(II, Constant::getNullValue(II.getType()));
----------------
paulwalker-arm wrote:
Sorry, my mistake. I was thinking about the compares in isolation and forgot about the and.
https://github.com/llvm/llvm-project/pull/213995
More information about the llvm-commits
mailing list