From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) by sourceware.org (Postfix) with ESMTPS id 344263858CD1 for ; Tue, 21 May 2024 01:13:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 344263858CD1 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 344263858CD1 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=198.175.65.18 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716254019; cv=none; b=mkRzSWgMFbD3u5ksgzwVzjHjJqyg33FtR/AyPgID6EwOvUfa3VQl0n86S7iJ8kQ975zVk6Ku/KUZ5Ux6hsgJvgiEqu8TpF/ICmgMHjFXLSIWa8MEFJ7jwDmnZncZ2fj+oT/Zfie2L7t2vedDLxFJ7AiFZ/Wq/gB1044/cwDdYJ0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716254019; c=relaxed/simple; bh=l9OS1LxdvdYdXwpYB1i9qRpw8z79f3dCjCEDu0UyNN0=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=I25Ll1YCF1YXnsn4hqF5TqIAnE8SlPuPfA+9EQomBoVMU38Dtvn/QYwtRFKAJexbyukR6+ZnDeImpsh3QKtNDJzE0W1RAsGdhIr7ki6GzwZQZktQe7kKXErinfrsGvLXAjmXx1DxVVV72OwXsFxtBAWlwbr8Dx3IN5yql50rjO0= 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=1716253999; x=1747789999; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=l9OS1LxdvdYdXwpYB1i9qRpw8z79f3dCjCEDu0UyNN0=; b=AEBehRkqu4hBra1W+mi2ZsZ5WLE66/clCdRhB9xqfce/AVly+TvpPS47 Wl60fW4bOGBUsSdUDmDprBm4ZrMteHcQlab8SiIoA9f7jwN89j1qoQQFy fbMcbT90f3+hFA3UtCRSphozXRoEqhUQloI85KhA3dhe7sVKzIv8o8MY2 NIrNoanp/JLKAmbJlBvzOG8n42dJ4IgX1xQUkcQOmUuUUpftkUlPXRD2U gVlY47vVAp5Z8V9eXoGGpya02CpQ11KmFyc/DlSonqsykWwlYVjZ6tvsM 2oRL7n4fWnj+SLI8ECg58FYyySdSHHHutGmxig7alDwU6Vbt+WweveD1e A==; X-CSE-ConnectionGUID: 2E92XGaBQA+13me9nXpMSA== X-CSE-MsgGUID: X+fj2YdtRCSL1gXbixEFeg== X-IronPort-AV: E=McAfee;i="6600,9927,11078"; a="12592984" X-IronPort-AV: E=Sophos;i="6.08,176,1712646000"; d="scan'208";a="12592984" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 May 2024 18:13:18 -0700 X-CSE-ConnectionGUID: ws6lxfPKRA+N+nOf/Cofjw== X-CSE-MsgGUID: 58zNqwtpSeyHgMsV8VrDkA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,176,1712646000"; d="scan'208";a="33326412" Received: from shvmail02.sh.intel.com ([10.239.244.9]) by orviesa007.jf.intel.com with ESMTP; 20 May 2024 18:13:14 -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 22115100A811; Tue, 21 May 2024 09:13:14 +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, Pan Li Subject: [PATCH v3] Match: Extract ternary_integer_types_match_p helper func [NFC] Date: Tue, 21 May 2024 09:13:10 +0800 Message-Id: <20240521011310.3455951-1-pan2.li@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-11.5 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 List-Id: 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: * match.pd: Leverage helper func for SAT_ADD match. * tree.cc (ternary_integer_types_match_p): New func impl to check if ternary tree types are all integer. * tree.h (ternary_integer_types_match_p): New func decl. Signed-off-by: Pan Li --- gcc/match.pd | 28 +++++++--------------------- gcc/tree.cc | 16 ++++++++++++++++ gcc/tree.h | 5 +++++ 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/gcc/match.pd b/gcc/match.pd index 0f9c34fa897..cff67c84498 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -39,7 +39,8 @@ along with GCC; see the file COPYING3. If not see HONOR_NANS uniform_vector_p expand_vec_cmp_expr_p - bitmask_inv_cst_vector_p) + bitmask_inv_cst_vector_p + ternary_integer_types_match_p) /* Operator lists. */ (define_operator_list tcc_comparison @@ -3046,38 +3047,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 (ternary_integer_types_match_p (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 (ternary_integer_types_match_p (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 (ternary_integer_types_match_p (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 (ternary_integer_types_match_p (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 (ternary_integer_types_match_p (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. diff --git a/gcc/tree.cc b/gcc/tree.cc index 6564b002dc1..b59d42c3e47 100644 --- a/gcc/tree.cc +++ b/gcc/tree.cc @@ -10622,6 +10622,22 @@ uniform_integer_cst_p (tree t) return NULL_TREE; } +/* Check if the types T1, T2 and T3 are effectively the same integer type. + If T1, T2 or T3 is not a type, the test applies to their TREE_TYPE. */ + +bool +ternary_integer_types_match_p (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_compatible_p (t1, t2) && types_compatible_p (t2, t3); +} + /* Checks to see if T is a constant or a constant vector and if each element E adheres to ~E + 1 == pow2 then return ~E otherwise NULL_TREE. */ diff --git a/gcc/tree.h b/gcc/tree.h index ee2aae332a4..4ac59ac55cb 100644 --- a/gcc/tree.h +++ b/gcc/tree.h @@ -5212,6 +5212,11 @@ extern bool integer_pow2p (const_tree); extern tree bitmask_inv_cst_vector_p (tree); +/* Check if the types T1, T2 and T3 are effectively the same integer type. + If T1, T2 or T3 is not a type, the test applies to their TREE_TYPE. */ + +extern bool ternary_integer_types_match_p (tree, tree, tree); + /* integer_nonzerop (tree x) is nonzero if X is an integer constant with a nonzero value. */ -- 2.34.1