From patchwork Mon May 20 10:59:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2" X-Patchwork-Id: 90475 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 331403858C3A for ; Mon, 20 May 2024 11:00:33 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.19]) by sourceware.org (Postfix) with ESMTPS id E8B573858D1E for ; Mon, 20 May 2024 11:00:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E8B573858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=intel.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org E8B573858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.19 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716202804; cv=none; b=eU2K8pyq2T4/mwcgYmWk9g0kayLIe65M0GdCVvyOGRGgGKxEb2c2HoNerC5wJJ4U92hyE1wgpFYzqpvXBG+Sx/y+1/y9i4VKljlop9PQYccRpd63hvhIlbT4orP9n5/giaAiLKfjumQfbcZtzbYN2AEcWtuNYK3klNZCfBgnckg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716202804; c=relaxed/simple; bh=WTpdVFl0N8aFBFvaMLhuxrJnseXFIu33yHV7oJhn8U8=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=hN9m38Q1CGjiJiZq1r5n+acPzwT0vnzQ4WxrvJVz/6Gs4pEv9oZXvY9w7HBEHGyJbIOVbgdb8aPU0/b8Vab2osu3vSvifOuNrpoJ66qf87vHhPXC9zW6Xbfh7Sl/tz8NE6xwxmi+yLi3BXC0RMstYWZblzARSu3iyKIf99DIJck= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1716202802; x=1747738802; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=WTpdVFl0N8aFBFvaMLhuxrJnseXFIu33yHV7oJhn8U8=; b=GMLnv1XP59ER4wlFjwfEZw7l7HCUuNNj8d8BgKHo8PaSEbkVEv5rIxhl w2c4BaEupnmhNMDTQ7akSf0LVTCj/9WnI2J9G0XsyyW1S6i2IBTpG+Gu9 fRko3coNJ+Z0NVnBsnjQ416WxYF5wFeGaHJTNeBoBmmhP+6gzAZKG3PMp h4B01dRfOywl+utOz9+rOMx1Cn8zwfCN7MAaE0HAyE9vpPshtQ9W9BPAO xTSggEWUP3eWNPDKzsrJG1jhQgxyp0bWGR0oVskud8tx4oU61WoPmwraa 9eP6b2PGU/wJ9TjTs/pBQWKDg/UtW+Rg+Wzf1hxM4OVz78IOmzlWEI2ap w==; X-CSE-ConnectionGUID: R/NXnlPEQla7E5cep++9VA== X-CSE-MsgGUID: 20+6IxOhTvWqv0lTa3eoCQ== X-IronPort-AV: E=McAfee;i="6600,9927,11077"; a="12171626" X-IronPort-AV: E=Sophos;i="6.08,174,1712646000"; d="scan'208";a="12171626" Received: from fmviesa004.fm.intel.com ([10.60.135.144]) by orvoesa111.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 May 2024 04:00:01 -0700 X-CSE-ConnectionGUID: WrYlfpw9T7+nUX2rzCKOow== X-CSE-MsgGUID: ZV8XGdXORVyDYG4+idfv1Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,174,1712646000"; d="scan'208";a="37085462" Received: from shvmail02.sh.intel.com ([10.239.244.9]) by fmviesa004.fm.intel.com with ESMTP; 20 May 2024 03:59:58 -0700 Received: from pli-ubuntu.sh.intel.com (pli-ubuntu.sh.intel.com [10.239.159.47]) by shvmail02.sh.intel.com (Postfix) with ESMTP id 88650100A7F2; Mon, 20 May 2024 18:59:57 +0800 (CST) From: pan2.li@intel.com To: gcc-patches@gcc.gnu.org Cc: juzhe.zhong@rivai.ai, kito.cheng@gmail.com, tamar.christina@arm.com, richard.guenther@gmail.com, pinskia@gmail.com, Pan Li Subject: [PATCH v2] Match: Extract integer_types_ternary_match helper to avoid code dup [NFC] Date: Mon, 20 May 2024 18:59:56 +0800 Message-Id: <20240520105956.2826662-1-pan2.li@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org 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..401b52e7573 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 (integer_types_ternary_match (type, @0, @1) && TYPE_UNSIGNED (type)))) (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 (integer_types_ternary_match (type, @0, @1) && TYPE_UNSIGNED (type)))) (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 (integer_types_ternary_match (type, @0, @1) && TYPE_UNSIGNED (type)))) (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 (integer_types_ternary_match (type, @0, @1) && TYPE_UNSIGNED (type)))) (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 (integer_types_ternary_match (type, @0, @1) && TYPE_UNSIGNED (type)))) /* 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.