[llvm] [SDAG] Allow S/Zext in select-abd pattern (PR #191207)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 10 04:55:03 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) {
----------------
DaKnig wrote:
please look at the code again.
```
if (/*...*/ sd_match(False,
m_AnyOf(m_Sub(RHSPat, LHSPat),
m_Add(RHSPat, m_SpecificNeg(LHS, true)))))
```
this code was written in a very similar way before this patch. this captures `(sub a, b)` (the canonical case) and `(add a, -b)` which happens when `(sub a, b)` happens to have constant b. hence, the `(add ...)` case is for constant values only. in addition, `m_SpecificNeg` already does both `m_Neg` and special treatment of the constant case.
https://github.com/llvm/llvm-project/pull/191207
More information about the llvm-commits
mailing list