From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oo1-xc32.google.com (mail-oo1-xc32.google.com [IPv6:2607:f8b0:4864:20::c32]) by sourceware.org (Postfix) with ESMTPS id 0B6FB3858C31 for ; Sun, 19 May 2024 04:25:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0B6FB3858C31 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 0B6FB3858C31 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::c32 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716092705; cv=none; b=Unre2Vcrf+kJh3fClP561X6p0lYsirn7gNGcQshaRGDvrlb4lQe3n/VwA5A4u4rW1WrZmsfQ+XwygR/y6KW8FKordNX7pXUekN8NXGKwdkhEVe5CTHF+PkHrmgnvxpS0kcZLzNvCnC5BfF+Jm5FMkKYGt2Gp00MHnZg+kiJ/IQ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716092705; c=relaxed/simple; bh=JeWqtj+kGUtsHPeNPDD/NWiH9diwxlzBVCIDhcONkeY=; h=DKIM-Signature:MIME-Version:From:Date:Message-ID:Subject:To; b=INaRO4xBQ5XFl8+TGtEf9F/055ziG9Jl8IrNFaQ2wkDsKS4EYskQf8d3A8tMbT2VZ1sIuH890GHb9rL89OJ3yQvUFVlCHIWbHZLhjPBcCvhYSVuPeJoUlr0EVv6qbu1cNYXp50nh6oR/ppYwdMS1IAnVkFkbNGG2KGTOfLVUbi4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-oo1-xc32.google.com with SMTP id 006d021491bc7-5b27e8ad4b6so888528eaf.0 for ; Sat, 18 May 2024 21:25:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1716092702; x=1716697502; darn=gcc.gnu.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=tGTk5pJJeuNyeHeQhLXqCJObnFHEKGYrN/zKKKZSm5U=; b=dd+/ozUimewGl3vJD5D9/mK8SjM+ePlSIqP4dmeQjVfdv1sTrAOunSqzjR48wHuG62 SnfmoaSdUsybQ3OFEB6IsCophubsg2Xw36vnz8BaP0cg8jJHL62g33xMqrQN75uVt5F+ ppEd72+usO64k+XFsRf+SHgh92vcjmJzYPi9lysWWKbYZ/qW2ZMh5zl98oNZY59ZWbEA iceLa4YGVQhOAelYnCGfs6yIQlQ//Ha5nqZyoZ4KffbWyoXHTPDPxQ5dMeATcozZZ6dl 42Yh6JW4cCColLOIP7ScBy0NrcYuao6fiPUd+1ul2X7g54nhKiyvx9eOf0MHn+sPXR5j 8S9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1716092702; x=1716697502; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=tGTk5pJJeuNyeHeQhLXqCJObnFHEKGYrN/zKKKZSm5U=; b=o49bCgznEY8WjBa6QJ8SF3Gf0g3mD6UsGbrP3uqaCc59eBwoIklmyazJZLVZ3mZSL9 8ahl/bLn2zfxhDwYXTXbqDcY7nqepg1mp6RkWs+CRO2ti+NazFZlgSxM7hcBqjR14N8X 3odcbudSFXlPpC/oQx552raOnUHVHD4h1CwBJ68lESq0NwNXLNGQvfSjrmU474g2wqQV RothBUzg0OE4SNF4bn/kRoW8sBddphPOkq+sGiufVtnajzxXZgBlAUhVTcRuHYY0VXp+ pvNMWVvQxxnABjR07Pq43PuuP/WWZxwppMvymI1PE6OXzCt6m1IvLZfkMqX3M8K4Z3WX c+TQ== X-Gm-Message-State: AOJu0YzJty9uSy19WWhGf6uEUzwsw2yZKnA39uo+w0XvH0uZJ5nmwo+t hpXnfe6eXs0Q+oN+P/cK+7f4ozUr3AfjrUwmxz87DQ8fK0I+hS/Ap899L9wgPFD4xiNFXTdJYTJ rIFx9patRN31HoP0Q50n3/GmcAzk= X-Google-Smtp-Source: AGHT+IHmUskN5qe12LjdFktnB42Lu8YFj7h/mggKzEkPBIafYCB5TVBOd69/QcceN8ODA0rNLXWbTHHVyshvF5zZ1sM= X-Received: by 2002:a05:6358:57a2:b0:18f:743b:bb7e with SMTP id e5c5f4694b2df-193bb63c434mr2567473655d.15.1716092701944; Sat, 18 May 2024 21:25:01 -0700 (PDT) MIME-Version: 1.0 References: <20240519041651.1743716-1-pan2.li@intel.com> In-Reply-To: <20240519041651.1743716-1-pan2.li@intel.com> From: Andrew Pinski Date: Sat, 18 May 2024 21:24:50 -0700 Message-ID: Subject: Re: [PATCH v1] Match: Extract integer_types_ternary_match helper to avoid code dup [NFC] To: "pan2.li" Cc: GCC Patches , =?UTF-8?B?6ZKf5bGF5ZOy?= , Kito Cheng , Tamar Christina , Richard Guenther Content-Type: multipart/alternative; boundary="000000000000e6b52e0618c6f776" X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --000000000000e6b52e0618c6f776 Content-Type: text/plain; charset="UTF-8" On Sat, May 18, 2024, 9:17 PM wrote: > From: Pan Li > > There are sorts of match pattern for SAT related cases, there will be > some duplicated code to check the dest, op_0, op_1 are same tree types. > Aka ternary tree type matches. Thus, extract one helper function to > do this and avoid match code duplication. > > The below test suites are passed for this patch: > * The rv64gcv fully regression test. > * The x86 bootstrap test. > * The x86 regression test. > > gcc/ChangeLog: > > * generic-match-head.cc (integer_types_ternary_match): New helper > function to check tenary tree type matches or not. > * gimple-match-head.cc (integer_types_ternary_match): Ditto but > for match. > * match.pd: Leverage above helper function to avoid code dup. > > Signed-off-by: Pan Li > --- > gcc/generic-match-head.cc | 17 +++++++++++++++++ > gcc/gimple-match-head.cc | 17 +++++++++++++++++ > gcc/match.pd | 25 +++++-------------------- > 3 files changed, 39 insertions(+), 20 deletions(-) > > diff --git a/gcc/generic-match-head.cc b/gcc/generic-match-head.cc > index 0d3f648fe8d..cdd48c7a5cc 100644 > --- a/gcc/generic-match-head.cc > +++ b/gcc/generic-match-head.cc > @@ -59,6 +59,23 @@ types_match (tree t1, tree t2) > return TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2); > } > > +/* Routine to determine if the types T1, T2 and T3 are effectively > + the same integer type for GENERIC. If T1, T2 or T3 is not a type, > + the test applies to their TREE_TYPE. */ > + > +static inline bool > +integer_types_ternary_match (tree t1, tree t2, tree t3) > +{ > + t1 = TYPE_P (t1) ? t1 : TREE_TYPE (t1); > + t2 = TYPE_P (t2) ? t2 : TREE_TYPE (t2); > + t3 = TYPE_P (t3) ? t3 : TREE_TYPE (t3); > + > + if (!INTEGRAL_TYPE_P (t1) || !INTEGRAL_TYPE_P (t2) || !INTEGRAL_TYPE_P > (t3)) > + return false; > + > + return types_match (t1, t2) && types_match (t1, t3); > +} > + > /* Return if T has a single use. For GENERIC, we assume this is > always true. */ > > diff --git a/gcc/gimple-match-head.cc b/gcc/gimple-match-head.cc > index 5f8a1a1ad8e..91f2e56b8ef 100644 > --- a/gcc/gimple-match-head.cc > +++ b/gcc/gimple-match-head.cc > @@ -79,6 +79,23 @@ types_match (tree t1, tree t2) > return types_compatible_p (t1, t2); > } > > +/* Routine to determine if the types T1, T2 and T3 are effectively > + the same integer type for GIMPLE. If T1, T2 or T3 is not a type, > + the test applies to their TREE_TYPE. */ > + > +static inline bool > +integer_types_ternary_match (tree t1, tree t2, tree t3) > +{ > + t1 = TYPE_P (t1) ? t1 : TREE_TYPE (t1); > + t2 = TYPE_P (t2) ? t2 : TREE_TYPE (t2); > + t3 = TYPE_P (t3) ? t3 : TREE_TYPE (t3); > + > + if (!INTEGRAL_TYPE_P (t1) || !INTEGRAL_TYPE_P (t2) || !INTEGRAL_TYPE_P > (t3)) > + return false; > + > + return types_match (t1, t2) && types_match (t1, t3); > +} > + > /* Return if T has a single use. For GIMPLE, we also allow any > non-SSA_NAME (ie constants) and zero uses to cope with uses > that aren't linked up yet. */ > diff --git a/gcc/match.pd b/gcc/match.pd > index 0f9c34fa897..b291e34bbe4 100644 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -3046,38 +3046,23 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > /* Unsigned Saturation Add */ > (match (usadd_left_part_1 @0 @1) > (plus:c @0 @1) > - (if (INTEGRAL_TYPE_P (type) > - && TYPE_UNSIGNED (TREE_TYPE (@0)) > - && types_match (type, TREE_TYPE (@0)) > - && types_match (type, TREE_TYPE (@1))))) > + (if (TYPE_UNSIGNED (type) && integer_types_ternary_match (type, @0, > @1)))) > Even though unsigned might be the cheaper check, you might need to swap the order back to where it was so you check integral first. Otherwise this is nice cleanup. (Note I can't approve it though). Thanks, Andrew > (match (usadd_left_part_2 @0 @1) > (realpart (IFN_ADD_OVERFLOW:c @0 @1)) > - (if (INTEGRAL_TYPE_P (type) > - && TYPE_UNSIGNED (TREE_TYPE (@0)) > - && types_match (type, TREE_TYPE (@0)) > - && types_match (type, TREE_TYPE (@1))))) > + (if (TYPE_UNSIGNED (type) && integer_types_ternary_match (type, @0, > @1)))) > > (match (usadd_right_part_1 @0 @1) > (negate (convert (lt (plus:c @0 @1) @0))) > - (if (INTEGRAL_TYPE_P (type) > - && TYPE_UNSIGNED (TREE_TYPE (@0)) > - && types_match (type, TREE_TYPE (@0)) > - && types_match (type, TREE_TYPE (@1))))) > + (if (TYPE_UNSIGNED (type) && integer_types_ternary_match (type, @0, > @1)))) > > (match (usadd_right_part_1 @0 @1) > (negate (convert (gt @0 (plus:c @0 @1)))) > - (if (INTEGRAL_TYPE_P (type) > - && TYPE_UNSIGNED (TREE_TYPE (@0)) > - && types_match (type, TREE_TYPE (@0)) > - && types_match (type, TREE_TYPE (@1))))) > + (if (TYPE_UNSIGNED (type) && integer_types_ternary_match (type, @0, > @1)))) > > (match (usadd_right_part_2 @0 @1) > (negate (convert (ne (imagpart (IFN_ADD_OVERFLOW:c @0 @1)) > integer_zerop))) > - (if (INTEGRAL_TYPE_P (type) > - && TYPE_UNSIGNED (TREE_TYPE (@0)) > - && types_match (type, TREE_TYPE (@0)) > - && types_match (type, TREE_TYPE (@1))))) > + (if (TYPE_UNSIGNED (type) && integer_types_ternary_match (type, @0, > @1)))) > > /* We cannot merge or overload usadd_left_part_1 and usadd_left_part_2 > because the sub part of left_part_2 cannot work with right_part_1. > -- > 2.34.1 > > --000000000000e6b52e0618c6f776--