[llvm] [InstCombine][AArch64] Combine ANDs with two constant CMPHS (PR #213995)
Matthew Devereau via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 6 03:58:15 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()));
----------------
MDevereau wrote:
I'm not sure if you've seen something which I haven't but I was under the impression that since CMPHS is zeroing inactive lanes and we're AND'ing them together:
- If ConstB > ConstA and the predicate is active for both compares, the AND will never be true
- If ConstB > ConstA and the predicate is inactive for either compare, the AND will never be true
https://github.com/llvm/llvm-project/pull/213995
More information about the llvm-commits
mailing list