From patchwork Fri Oct 11 06:22:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2" X-Patchwork-Id: 1995897 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=XKWlB8MZ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 4XPxS201F0z1xsc for ; Fri, 11 Oct 2024 17:24:48 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0779E3856DF0 for ; Fri, 11 Oct 2024 06:24:47 +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.19]) by sourceware.org (Postfix) with ESMTPS id 362A83858C2B for ; Fri, 11 Oct 2024 06:24:20 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 362A83858C2B 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 362A83858C2B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.19 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728627862; cv=none; b=pXX84OOAbdwnfrZBv0ve7XwvruKC2esT1l+pTszdnmeRzSPLkq6ibeHfixb03AI33fwscaDSHRCRbZQo2EZQH6KEKX4MlRARYEXEn9W3Lfe6wsa7ZUfzQTMwQBmpioU5uKtpyoUVeuIbgxPyhnK1dUXLX1X0c/4n895qisNrRfc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1728627862; c=relaxed/simple; bh=dw62URdP8ghYnCDmaLXbHVXa3G4UhN356nIQPtjJkr8=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=m6Vvn6uZwTCQT1CObS/hsG+bE68W2OFP2hA+9VkqZ/irZzMe2K34xwCR6p5TP/V9ZFiW9rtWDy37LXv3plvNEqk+bmsw3jeZbjSqBk75/D6nSgDb+74q4DZCJmUxScUrFXWGI88KtdC+rXUWJGNtB2gpBW6lDzO1xBTnyPUnwTE= 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=1728627860; x=1760163860; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=dw62URdP8ghYnCDmaLXbHVXa3G4UhN356nIQPtjJkr8=; b=XKWlB8MZh/Xp46TS4/g/N3gr29nWX3bpJ3YWsf2KpNZ8OBvd2aUMaAiz 8bRRO+A0zRP2VbqnI+qDEa5AALaetXTVEe9VFqK4ZCRo/uqNzupnz9wXu UWQ+rO+2tRxTpZ5zlbxsIC21jGUdi4i4KIXw7GBJ3Dtnw6RIi7O4dSstm 6+7P4HJ2LMkoqixeRtL4/EBsJhtymriza4PvQusGazvNSstz0Gcj9KYUA NSanaEwuI44zacTZiA/ZpNxKkt6jRWZzEheyUCyKcGeQ/DS1jUZZ5S0v4 EAINPKq2WJNmMgrjpUPBOKHpcZ3aijL0AP3mtzqlVLL3AwhAf2sAzwv/S Q==; X-CSE-ConnectionGUID: 6AadT23PQRGymfptE6RtQQ== X-CSE-MsgGUID: CjmolwH0QaSEhynuVkQY8Q== X-IronPort-AV: E=McAfee;i="6700,10204,11221"; a="27486380" X-IronPort-AV: E=Sophos;i="6.11,195,1725346800"; d="scan'208";a="27486380" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa113.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Oct 2024 23:24:19 -0700 X-CSE-ConnectionGUID: DdY7gKKBRPW7BdjRTur7CQ== X-CSE-MsgGUID: W9F1j9n4SUiOpW5wf89pWA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.11,195,1725346800"; d="scan'208";a="76442869" Received: from panli.sh.intel.com ([10.239.154.73]) by fmviesa006.fm.intel.com with ESMTP; 10 Oct 2024 23:24:17 -0700 From: pan2.li@intel.com To: gcc-patches@gcc.gnu.org Cc: richard.guenther@gmail.com, Tamar.Christina@arm.com, juzhe.zhong@rivai.ai, kito.cheng@gmail.com, jeffreyalaw@gmail.com, rdapp.gcc@gmail.com, Pan Li Subject: [PATCH v1 2/4] Vect: Try the pattern of vector signed integer SAT_SUB Date: Fri, 11 Oct 2024 14:22:43 +0800 Message-ID: <20241011062245.2486653-2-pan2.li@intel.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241011062245.2486653-1-pan2.li@intel.com> References: <20241011062245.2486653-1-pan2.li@intel.com> MIME-Version: 1.0 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 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 Almost the same as vector unsigned integer SAT_SUB, try to match the signed version during the vector pattern matching. The below test suites are passed for this patch. * The rv64gcv fully regression test. * The x86 bootstrap test. * The x86 fully regression test. gcc/ChangeLog: * tree-vect-patterns.cc (gimple_signed_integer_sat_sub): Add new func decl for signed SAT_SUB. (vect_recog_sat_sub_pattern_transform): Update comments. (vect_recog_sat_sub_pattern): Try the vector signed SAT_SUB pattern. Signed-off-by: Pan Li --- gcc/tree-vect-patterns.cc | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/gcc/tree-vect-patterns.cc b/gcc/tree-vect-patterns.cc index 9bf8526ac99..746f100a084 100644 --- a/gcc/tree-vect-patterns.cc +++ b/gcc/tree-vect-patterns.cc @@ -4538,6 +4538,7 @@ extern bool gimple_unsigned_integer_sat_sub (tree, tree*, tree (*)(tree)); extern bool gimple_unsigned_integer_sat_trunc (tree, tree*, tree (*)(tree)); extern bool gimple_signed_integer_sat_add (tree, tree*, tree (*)(tree)); +extern bool gimple_signed_integer_sat_sub (tree, tree*, tree (*)(tree)); static gimple * vect_recog_build_binary_gimple_stmt (vec_info *vinfo, stmt_vec_info stmt_info, @@ -4684,6 +4685,7 @@ vect_recog_sat_sub_pattern_transform (vec_info *vinfo, /* * Try to detect saturation sub pattern (SAT_ADD), aka below gimple: + * Unsigned: * _7 = _1 >= _2; * _8 = _1 - _2; * _10 = (long unsigned int) _7; @@ -4691,6 +4693,27 @@ vect_recog_sat_sub_pattern_transform (vec_info *vinfo, * * And then simplied to * _9 = .SAT_SUB (_1, _2); + * + * Signed: + * x.0_4 = (unsigned char) x_16; + * y.1_5 = (unsigned char) y_18; + * _6 = x.0_4 - y.1_5; + * minus_19 = (int8_t) _6; + * _7 = x_16 ^ y_18; + * _8 = x_16 ^ minus_19; + * _44 = _7 < 0; + * _23 = x_16 < 0; + * _24 = (signed char) _23; + * _58 = (unsigned char) _24; + * _59 = -_58; + * _25 = (signed char) _59; + * _26 = _25 ^ 127; + * _42 = _8 < 0; + * _41 = _42 & _44; + * iftmp.2_11 = _41 ? _26 : minus_19; + * + * And then simplied to + * iftmp.2_11 = .SAT_SUB (x_16, y_18); */ static gimple * @@ -4705,7 +4728,8 @@ vect_recog_sat_sub_pattern (vec_info *vinfo, stmt_vec_info stmt_vinfo, tree ops[2]; tree lhs = gimple_assign_lhs (last_stmt); - if (gimple_unsigned_integer_sat_sub (lhs, ops, NULL)) + if (gimple_unsigned_integer_sat_sub (lhs, ops, NULL) + || gimple_signed_integer_sat_sub (lhs, ops, NULL)) { vect_recog_sat_sub_pattern_transform (vinfo, stmt_vinfo, lhs, ops); gimple *stmt = vect_recog_build_binary_gimple_stmt (vinfo, stmt_vinfo,