From patchwork Thu Jul 18 12:26:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2" X-Patchwork-Id: 1962095 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=OvFugvR0; 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 4WPsWd2p9kz20B2 for ; Thu, 18 Jul 2024 22:27:25 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 94421385E839 for ; Thu, 18 Jul 2024 12:27:23 +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.11]) by sourceware.org (Postfix) with ESMTPS id 0E0703858D28 for ; Thu, 18 Jul 2024 12:27:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 0E0703858D28 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 0E0703858D28 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=192.198.163.11 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721305624; cv=none; b=lhkOS1mKrcP09YfnRsYMtxFjQJfr2dOs/p+c0zSv91WgQEAjbswjh+yjK3fC7KWutlq9bkzAjWDbSxSI2+LkPoDbdIpwRGb4zXTu0OIvv0r5LJsPCqbQX+tT3+IlzH/8fNd3SYbokgkpWFoRK4U/AvL/9G+G1M1cWW5+8KAgDXk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721305624; c=relaxed/simple; bh=1B2NjyrylqdShayoYQgZ9F8JQyL8k0AV3i8TJifzt0c=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=Pe1H+Vwj6fS6t7vKq8k2mgogJMggh6qS3p03x5Vq6lOC2O/khxOvmo4ntcdxOM9qZ2TKOQF/LSczp0lVFZm3n4VspqnuSeJbZ6utzeOYqR+eb5tvaEZuqIitY+dFw9ivIuBIfkIuE75hrflTg2tM3DES0HOVp2LETc6LGafeJEU= 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=1721305622; x=1752841622; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=1B2NjyrylqdShayoYQgZ9F8JQyL8k0AV3i8TJifzt0c=; b=OvFugvR04yFSOqcPNIBBmlHpEbtdUcib5y4/MkHlGl4ecKVyQgO8jMY8 hgoyi2IZiFElHxMEe7kywCM1Hk4RZjz9B8d4HT69mmbcik7zhuSFIJq5X NiqQQgSWTQQb7Y0sCS+DpaAh/wstXfYuUFaG/rupfdMPlptAAEuDpoKw2 nlEG33hT7BZqzDUXERQwIawO7ZK9ddkO5CAJ32wqgsy5hUr0uMrZ6E/gf 9Scfwv4eRdsESXOc3sNy1ts0i2HPb0m2blEBHpMGxDPd3FL6FidSTDdsr 13BV6BBkXQMg1E1cxyTL8dadNkBQ5Nh3ZJEujjQ78gsSnBVuJee9GEWDy w==; X-CSE-ConnectionGUID: G0rAXkHORjGRyukM9h5QaA== X-CSE-MsgGUID: xcpog26ZTA6/hNCZvh0miQ== X-IronPort-AV: E=McAfee;i="6700,10204,11136"; a="29474113" X-IronPort-AV: E=Sophos;i="6.09,217,1716274800"; d="scan'208";a="29474113" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 18 Jul 2024 05:26:54 -0700 X-CSE-ConnectionGUID: to1Xxpy8QbWSechr6ZJOdA== X-CSE-MsgGUID: 87hZ6fb5RXSwWYtVbtTwJA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.09,217,1716274800"; d="scan'208";a="51361393" Received: from shvmail02.sh.intel.com ([10.239.244.9]) by orviesa007.jf.intel.com with ESMTP; 18 Jul 2024 05:26:51 -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 BE75B1005060; Thu, 18 Jul 2024 20:26:50 +0800 (CST) From: pan2.li@intel.com To: gcc-patches@gcc.gnu.org Cc: juzhe.zhong@rivai.ai, kito.cheng@gmail.com, richard.guenther@gmail.com, tamar.christina@arm.com, jeffreyalaw@gmail.com, rdapp.gcc@gmail.com, hongtao.liu@intel.com, Pan Li Subject: [PATCH v1] Match: Only allow single use of MIN_EXPR for SAT_TRUNC form 2 [PR115863] Date: Thu, 18 Jul 2024 20:26:48 +0800 Message-Id: <20240718122648.1606100-1-pan2.li@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, 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 The SAT_TRUNC form 2 has below pattern matching. From: _18 = MIN_EXPR ; iftmp.0_11 = (unsigned int) _18; To: _18 = MIN_EXPR ; iftmp.0_11 = .SAT_TRUNC (_18); But if there is another use of _18 like below, the transform to the .SAT_TRUNC may have no earnings. For example: From: _18 = MIN_EXPR ; // op_0 def iftmp.0_11 = (unsigned int) _18; // op_0 stream.avail_out = iftmp.0_11; left_37 = left_8 - _18; // op_0 use To: _18 = MIN_EXPR ; // op_0 def iftmp.0_11 = .SAT_TRUNC (_18); stream.avail_out = iftmp.0_11; left_37 = left_8 - _18; // op_0 use Pattern recog to .SAT_TRUNC cannot eliminate MIN_EXPR as above. Then the backend (for example x86/riscv) will have additional 2-3 more insns after pattern recog besides the MIN_EXPR. Thus, keep the normal truncation as is should be the better choose. The below testsuites are passed for this patch: 1. The rv64gcv fully regression tests. 2. The x86 bootstrap tests. 3. The x86 fully regression tests. PR target/115863 gcc/ChangeLog: * match.pd: Add single_use of MIN_EXPR for .SAT_TRUNC form 2. gcc/testsuite/ChangeLog: * gcc.target/i386/pr115863-1.c: New test. Signed-off-by: Pan Li --- gcc/match.pd | 15 +++++++-- gcc/testsuite/gcc.target/i386/pr115863-1.c | 37 ++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr115863-1.c diff --git a/gcc/match.pd b/gcc/match.pd index 5cb399b8718..d4f040b5c7b 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -3252,10 +3252,21 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) /* Unsigned saturation truncate, case 2, sizeof (WT) > sizeof (NT). SAT_U_TRUNC = (NT)(MIN_EXPR (X, 255)). */ +/* If Op_0 def is MIN_EXPR and not single_use. Aka below pattern: + + _18 = MIN_EXPR ; // op_0 def + iftmp.0_11 = (unsigned int) _18; // op_0 + stream.avail_out = iftmp.0_11; + left_37 = left_8 - _18; // op_0 use + + Transfer to .SAT_TRUNC will have MIN_EXPR still live. Then the backend + (for example x86/riscv) will have 2-3 more insns generation for .SAT_TRUNC + besides the MIN_EXPR. Thus, keep the normal truncation as is should be + the better choose. */ (match (unsigned_integer_sat_trunc @0) - (convert (min @0 INTEGER_CST@1)) + (convert (min@2 @0 INTEGER_CST@1)) (if (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type) - && TYPE_UNSIGNED (TREE_TYPE (@0))) + && TYPE_UNSIGNED (TREE_TYPE (@0)) && single_use (@2)) (with { unsigned itype_precision = TYPE_PRECISION (TREE_TYPE (@0)); diff --git a/gcc/testsuite/gcc.target/i386/pr115863-1.c b/gcc/testsuite/gcc.target/i386/pr115863-1.c new file mode 100644 index 00000000000..a672f62cec5 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr115863-1.c @@ -0,0 +1,37 @@ +/* PR target/115863 */ +/* { dg-do compile } */ +/* { dg-options "-O3 -fdump-rtl-expand-details" } */ + +#include + +typedef struct z_stream_s { + uint32_t avail_out; +} z_stream; + +typedef z_stream *z_streamp; + +extern int deflate (z_streamp strmp); + +int compress2 (uint64_t *destLen) +{ + z_stream stream; + int err; + const uint32_t max = (uint32_t)(-1); + uint64_t left; + + left = *destLen; + + stream.avail_out = 0; + + do { + if (stream.avail_out == 0) { + stream.avail_out = left > (uint64_t)max ? max : (uint32_t)left; + left -= stream.avail_out; + } + err = deflate(&stream); + } while (err == 0); + + return err; +} + +/* { dg-final { scan-rtl-dump-not ".SAT_TRUNC " "expand" } } */