From patchwork Mon Jul 22 12:48:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajit Agarwal X-Patchwork-Id: 1963256 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=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=GwtX4EEM; 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 4WSKph2RgZz1yZ7 for ; Mon, 22 Jul 2024 22:48:58 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F075F385DDD2 for ; Mon, 22 Jul 2024 12:48:56 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 77CE53858D26 for ; Mon, 22 Jul 2024 12:48:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 77CE53858D26 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=linux.ibm.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linux.ibm.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 77CE53858D26 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.156.1 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721652519; cv=none; b=FCwazq50Ajx4fc+ub/gzIMR4F7pE+dAU8sUhz9f7mCUei0XNVx8PCoHtJZMBKgcCVD5K8ywUMh2vhUXgVKDkyG+E7z28DhWVcNr4FGqUMKJNvQwR3al4pRj7s3s9LR5+sp5GQT37byQ4EecZPv1IAk0zojK6ABeOLZyjN0FzrHc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721652519; c=relaxed/simple; bh=nqbn4Z2JGNs6gd9nJEolYtXNNH9773nZIDioarOwpb0=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=GLfQO4H0O7Wl0GYEc+Sc2/360qjmfXht5Q5lVhKvba3aZwoYimH8tTF2ZF6nAzfitgXfaUTng17jXpzNv5gqWE9JkHi3Xmn5zrg73mpLwjwewubVALrM/6ZCGYj+8LB2gyO7UaiTFG9eQYKl8YWc4/UD81B/gnvJKY2L2hMNt1U= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0360083.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 46MCJMfW004330; Mon, 22 Jul 2024 12:48:29 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h= message-id:date:mime-version:to:from:subject:content-type :content-transfer-encoding; s=pp1; bh=VO9TGl380Bzt/XH0L6Zaq23XiN eWUIw2o24PxAWtCj8=; b=GwtX4EEMLUZ7PR3aakzZEAPig2kn759S/h+yaCFDWX e7+0EexI2f6AKfGTC4JWMZcJCLRCG36suM+YQuHU2U8jZhQTFJeupCk7u1fyPAVw C3F8DuEX+juDiSblLQxoMUj6ojGHSVuECh4tIXnDnnWjE9ii2tFXubYDE9EZmMMp esGa4tKHpZDqK5LbFOmX+l5NWbUfNElJjg0Ewt2HsMmrlX6nDh9vrGof6zVuOCSE JJbTXc9x+FqNMzoaPlSnnu4gmEvReV/2JtgI1DVQKTc0K/+Hoj/CDY28PB7XcG04 Feh+uvYDlbz0nrxnkt15CFDnQxcE0TKgMmGlNZi2ki2A== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 40hkxm0j47-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 22 Jul 2024 12:48:29 +0000 (GMT) Received: from m0360083.ppops.net (m0360083.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 46MCk9M6010917; Mon, 22 Jul 2024 12:48:28 GMT Received: from ppma12.dal12v.mail.ibm.com (dc.9e.1632.ip4.static.sl-reverse.com [50.22.158.220]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 40hkxm0j45-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 22 Jul 2024 12:48:28 +0000 (GMT) Received: from pps.filterd (ppma12.dal12v.mail.ibm.com [127.0.0.1]) by ppma12.dal12v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 46M9u6Zs006216; Mon, 22 Jul 2024 12:48:27 GMT Received: from smtprelay04.wdc07v.mail.ibm.com ([172.16.1.71]) by ppma12.dal12v.mail.ibm.com (PPS) with ESMTPS id 40gqju6s11-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 22 Jul 2024 12:48:27 +0000 Received: from smtpav03.wdc07v.mail.ibm.com (smtpav03.wdc07v.mail.ibm.com [10.39.53.230]) by smtprelay04.wdc07v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 46MCmOwj32834178 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 22 Jul 2024 12:48:26 GMT Received: from smtpav03.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6AD2A58054; Mon, 22 Jul 2024 12:48:24 +0000 (GMT) Received: from smtpav03.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0DBAE58062; Mon, 22 Jul 2024 12:48:22 +0000 (GMT) Received: from [9.43.18.174] (unknown [9.43.18.174]) by smtpav03.wdc07v.mail.ibm.com (Postfix) with ESMTP; Mon, 22 Jul 2024 12:48:21 +0000 (GMT) Message-ID: <0ea033e2-594e-4b25-b452-3df61f5f4825@linux.ibm.com> Date: Mon, 22 Jul 2024 18:18:20 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: "Kewen.Lin" , Segher Boessenkool , Michael Meissner , Peter Bergner , David Edelsohn , gcc-patches From: Ajit Agarwal Subject: [Patch, rs6000] Improve suggested unroll factor in finish_cost X-TM-AS-GCONF: 00 X-Proofpoint-GUID: KcX7hKjbgYkCavgsIAEoFJN2XmYppgaC X-Proofpoint-ORIG-GUID: x0ZMzzKs26CZ415n_-6pSdkNoEpFzBUw X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-07-22_08,2024-07-22_01,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 clxscore=1015 suspectscore=0 mlxscore=0 bulkscore=0 mlxlogscore=999 adultscore=0 malwarescore=0 lowpriorityscore=0 impostorscore=0 spamscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2407110000 definitions=main-2407220093 X-Spam-Status: No, score=-12.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, KAM_MANYTO, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, 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 Hello All: This patch improve determine_suggested_unroll_factor in finish_cost with reduction factor of loads/stores/non_load_stores. Return unroll factor calculated as per reduction factor with number of loads/stores/non_load_stores (general_ops). Bootstrapped and regtested on powerpc64-linux-gnu. Expected gains with spec 2017 benchmarks. Thanks & Regards Ajit rs6000: Improve suggested unroll factor in finish_cost Improve determine_suggested_unroll_factor in finish_cost with reduction factor of loads/stores/non_load_stores. Return unroll factor calculated as per reduction factor with number of loads/stores/non_load_stores (general_ops). 2024-07-22 Ajit Kumar Agarwal gcc/ChangeLog: * config/rs6000/rs6000.cc: Improve determine_suggested_unroll_factor with reduction factor of load/stores/general_ops. --- gcc/config/rs6000/rs6000.cc | 60 ++++++++++--------------------------- 1 file changed, 16 insertions(+), 44 deletions(-) diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc index 5ed64b1e686..0d69ec4cfbe 100644 --- a/gcc/config/rs6000/rs6000.cc +++ b/gcc/config/rs6000/rs6000.cc @@ -5458,7 +5458,6 @@ rs6000_cost_data::adjust_vect_cost_per_loop (loop_vec_info loop_vinfo) - estimated iteration count when iteration count is unknown; */ - unsigned int rs6000_cost_data::determine_suggested_unroll_factor (loop_vec_info loop_vinfo) { @@ -5483,53 +5482,26 @@ rs6000_cost_data::determine_suggested_unroll_factor (loop_vec_info loop_vinfo) unsigned int issue_width = rs6000_vect_unroll_issue; unsigned int uf = CEIL (reduc_factor * issue_width, nstmts_nonldst); uf = MIN ((unsigned int) rs6000_vect_unroll_limit, uf); - /* Make sure it is power of 2. */ - uf = 1 << ceil_log2 (uf); + unsigned int temp; - /* If the iteration count is known, the costing would be exact enough, - don't worry it could be worse. */ - if (LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo)) - return uf; - - /* Inspired by SPEC2017 parest_r, we want to aggressively unroll the - loop if either condition is satisfied: - - reduction factor exceeds the threshold; - - emulated gather load adopted. */ - if (reduc_factor > (unsigned int) rs6000_vect_unroll_reduc_threshold - || m_gather_load) - return uf; - - /* Check if we can conclude it's good to unroll from the estimated - iteration count. */ - HOST_WIDE_INT est_niter = get_estimated_loop_iterations_int (loop); - unsigned int vf = vect_vf_for_cost (loop_vinfo); - unsigned int unrolled_vf = vf * uf; - if (est_niter == -1 || est_niter < unrolled_vf) - /* When the estimated iteration of this loop is unknown, it's possible - that we are able to vectorize this loop with the original VF but fail - to vectorize it with the unrolled VF any more if the actual iteration - count is in between. */ - return 1; - else + if (m_nstores > 0) { - unsigned int epil_niter_unr = est_niter % unrolled_vf; - unsigned int epil_niter = est_niter % vf; - /* Even if we have partial vector support, it can be still inefficent - to calculate the length when the iteration count is unknown, so - only expect it's good to unroll when the epilogue iteration count - is not bigger than VF (only one time length calculation). */ - if (LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) - && epil_niter_unr <= vf) - return uf; - /* Without partial vector support, conservatively unroll this when - the epilogue iteration count is less than the original one - (epilogue execution time wouldn't be longer than before). */ - else if (!LOOP_VINFO_CAN_USE_PARTIAL_VECTORS_P (loop_vinfo) - && epil_niter_unr <= epil_niter) - return uf; + temp = CEIL (reduc_factor * rs6000_vect_unroll_issue, + m_nstores); + uf = MIN (uf, temp); } - return 1; + if (m_nloads > 0) + { + temp = CEIL (reduc_factor * rs6000_vect_unroll_issue, + m_nloads + m_nstores); + uf = MIN (uf, temp); + } + + /* Make sure it is power of 2. */ + uf = 1 << ceil_log2 (uf); + + return uf; } void