[llvm] [SDAG] Allow S/Zext in select-abd pattern (PR #191207)
Simon Pilgrim via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 17 07:21:45 PDT 2026
================
@@ -1463,25 +1464,33 @@ inline auto m_IntrinsicWOChain(const OpndPreds &...Opnds) {
struct SpecificNeg_match {
SDValue V;
+ bool AllowTypeMismatch;
- explicit SpecificNeg_match(SDValue V) : V(V) {}
+ explicit SpecificNeg_match(SDValue V, bool AllowTypeMismatch = false)
+ : V(V), AllowTypeMismatch(AllowTypeMismatch) {}
template <typename MatchContext>
bool match(const MatchContext &Ctx, SDValue N) {
if (sd_context_match(N, Ctx, m_Neg(m_Specific(V))))
return true;
return ISD::matchBinaryPredicate(
- V, N, [](ConstantSDNode *LHS, ConstantSDNode *RHS) {
- return LHS->getAPIntValue() == -RHS->getAPIntValue();
- });
+ V, N,
+ [](ConstantSDNode *LHS, ConstantSDNode *RHS) {
+ APInt RHSInt = RHS->getAPIntValue();
+ APInt LHSInt = LHS->getAPIntValue();
+ unsigned Width = std::max(RHSInt.getBitWidth(), LHSInt.getBitWidth());
+ return LHSInt.sext(Width) == -RHSInt.sext(Width);
+ },
+ /*AllowUndefs*/ false, AllowTypeMismatch);
}
};
/// Match a negation of a specific value V, either as sub(0, V) or as
/// constant(s) that are the negation of V's constant(s).
-inline SpecificNeg_match m_SpecificNeg(SDValue V) {
- return SpecificNeg_match(V);
+inline SpecificNeg_match m_SpecificNeg(SDValue V,
+ bool AllowTypeMismatch = false) {
----------------
RKSimon wrote:
@DaKnig where is the test coverage for the matching constant at different bitwidth?
https://github.com/llvm/llvm-project/pull/191207
More information about the llvm-commits
mailing list