From patchwork Thu May 23 00:24:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2" X-Patchwork-Id: 1938139 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=e7IyQYvB; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Vl87r1RGKz20KL for ; Thu, 23 May 2024 10:24:54 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E4CF53858C62 for ; Thu, 23 May 2024 00:24:49 +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 [192.198.163.18]) by sourceware.org (Postfix) with ESMTPS id A75103858D26 for ; Thu, 23 May 2024 00:24:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A75103858D26 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 A75103858D26 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.18 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716423870; cv=none; b=tsA+4a8G0l6NsVtyoqAi9cqhz8MVuUy/ENjvSDgqBB1L9JmsDFFQM+0mp2F45HunfqxGKMZaGZz9oy0xekVzm+TIkvgmQq9MtPDpPzyhOC2MmVNAmtHvuFCJisWBN/WjOxnHgv78Z69XLxH97zgXR7HxN0P/6ky4oF9YVxUlqYY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1716423870; c=relaxed/simple; bh=O/xeQE/Gd0Cux6+K/0da9sqlBok8XRwB5OkAcTMCC/I=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=qyKDk2SGgZDRs88flKeXI7y/F4vcgplOMh7eVbflPBAXgfSs6zXWoEkqfiubSKLqp6R2Cha4dQi4tw/dwZrK9SiSgI8m+JNNQkAx3+eWZ90biprNrtKPYu+KLiRGi0TWttLwt0VaylV/mxI0gDOkSzDxNQESduO9Rb3YPaeX3uk= 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=1716423869; x=1747959869; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=O/xeQE/Gd0Cux6+K/0da9sqlBok8XRwB5OkAcTMCC/I=; b=e7IyQYvBsZLutGgZqh1+XxVhloTmdz57hAYvTxNVSrGrYg4qRZI36Oh5 lotbWEBaHvp3ScwjBYmARoiS3nNBEdz3S3wvICxFynh3oemc5miv8l178 GLjZMF0dmyZZCKdbdIN+4XsyeHLQXwiODlvB93lFplDT+8Q4HuTN4/mAq BxKw6WU2Wp7KuRE0pUEcEdhmUU2xh95r7Oau97w3CLBqonDUHjCpH7GgE IaCydq8nxZu+uRAU7twVJyRt/2kKB4vrEKp7PTX0zF/1v8sxUMshsHCg5 Jo9N8hWO1r86t6I44neXWJMp+rR1Hf+bOzR0JoVrPF87EXNEm0s2ondyW A==; X-CSE-ConnectionGUID: nKye1HqMTk2VXRp1x+vvJQ== X-CSE-MsgGUID: TwfF3eOMTTO+Uws/F2KGCg== X-IronPort-AV: E=McAfee;i="6600,9927,11080"; a="12491804" X-IronPort-AV: E=Sophos;i="6.08,181,1712646000"; d="scan'208";a="12491804" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 May 2024 17:24:27 -0700 X-CSE-ConnectionGUID: 3V84pXmGR2qz2lpy7i7Bnw== X-CSE-MsgGUID: 0PwV72iuQkORTCvQsDJCMw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,181,1712646000"; d="scan'208";a="33928796" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by orviesa006.jf.intel.com with ESMTP; 22 May 2024 17:24:24 -0700 Received: from pli-ubuntu.sh.intel.com (pli-ubuntu.sh.intel.com [10.239.159.47]) by shvmail03.sh.intel.com (Postfix) with ESMTP id D26241006FEC; Thu, 23 May 2024 08:24:22 +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 v4] Match: Add overloaded types_match to avoid code dup [NFC] Date: Thu, 23 May 2024 08:24:21 +0800 Message-Id: <20240523002421.1477387-1-pan2.li@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.3 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+incoming=patchwork.ozlabs.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, add overloaded types_match func 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 (types_match): Add overloaded types_match for 3 types. * gimple-match-head.cc (types_match): Ditto. * match.pd: Leverage overloaded types_match. Signed-off-by: Pan Li --- gcc/generic-match-head.cc | 14 ++++++++++++++ gcc/gimple-match-head.cc | 14 ++++++++++++++ gcc/match.pd | 30 ++++++++++-------------------- 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/gcc/generic-match-head.cc b/gcc/generic-match-head.cc index 0d3f648fe8d..8d8ecfaeb1d 100644 --- a/gcc/generic-match-head.cc +++ b/gcc/generic-match-head.cc @@ -59,6 +59,20 @@ 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 for GENERIC. If T1, T2 or T2 is not a type, the test + applies to their TREE_TYPE. */ + +static inline bool +types_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); + + return types_match (t1, t2) && types_match (t2, 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..2b7f746ab13 100644 --- a/gcc/gimple-match-head.cc +++ b/gcc/gimple-match-head.cc @@ -79,6 +79,20 @@ 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 for GIMPLE. If T1, T2 or T2 is not a type, the test + applies to their TREE_TYPE. */ + +static inline bool +types_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); + + return types_match (t1, t2) && types_match (t2, 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 35e3d82b131..7081d76d56a 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3048,38 +3048,28 @@ 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 (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type) + && types_match (type, @0, @1)))) (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 (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type) + && types_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 (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type) + && types_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 (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type) + && types_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 (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type) + && types_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.