[llvm] [SDAG] Allow S/Zext in select-abd pattern (PR #191207)

via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 10 04:03:54 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);
----------------
DaKnig wrote:

done

https://github.com/llvm/llvm-project/pull/191207


More information about the llvm-commits mailing list