From patchwork Wed Jul 24 09:42:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ajit Agarwal X-Patchwork-Id: 1964210 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=O7e8JeL0; 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 4WTTcX6VnDz1yXx for ; Wed, 24 Jul 2024 19:44:12 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2FEEA3858427 for ; Wed, 24 Jul 2024 09:44:11 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 70D6D3858C5F for ; Wed, 24 Jul 2024 09:43:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 70D6D3858C5F 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 70D6D3858C5F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721814183; cv=none; b=ZN1IK3fTtd32YdjQT35W9sUqDJTPLPsQNA+pDf460vLqlx5V1LpZCfqb1kaRyxJ78HGJauMLvxFfBBb6dKxbYrD/GyftZwv9LB5YZ8/JYxCjCtIiF6JukivhX1NmAEamnAMv68fBxSkksCg5rRgE59N2k31iviZ9fBE4sNc1Omo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721814183; c=relaxed/simple; bh=JSJokN3PfIY8VLpmy7MqrxdhN+2Ek8CbZ/ApN6W9kGE=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=W0ulZrQxyT9uI74FqVcUs4MxT/fV6B0iucFTOOU1nU6iLq49W0TnXVCknORkEMyvW8pYLZknwN12ZL1lFEBzHY8490x3ImZtbIk+ry9G/xzXWur9dpFMWgsqDCsMxQcWM9YNOKj5ZmbGhWOP8O2YtfBkphxbWxhIT0PuvjtEyGM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from pps.filterd (m0353723.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 46O8wmY6031254; Wed, 24 Jul 2024 09:43:01 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=WeVBg3TLO2Yv0f74f5dBbcnQzT fAMu9O9ceBsUIuTWU=; b=O7e8JeL0B4R0bYVoeQB0xG728Wc9gB+PpY6Oj5KjgR 5aeif3r69/x1zkdK1+w9ZH+FODb2n+E5e18n8/hPZjsol+qW1JbE7ZZFHm6u9qGm jbtKwOZIhZO8pDKMVT+XjaqKJJZobJno19lWTioplBgpaTgxvWDSXqKymZvXWEQy iQVPSGHiYLS/0UrWA7Z1gqM6jJ2X8r5l9BF8Q+I78XsuB+zufmpRAJt5pCcVC7J0 zjpNxXUJckKjTSQzJGwG21BLshqDt7RsEXu1mYVk/f7KX/109gGjoSyojk13VfI9 A1I+FQpzxQfsEgiD/zAQoHzLuL5h0pbB3H1hok06UNDA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 40jxjr03an-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 24 Jul 2024 09:43:00 +0000 (GMT) Received: from m0353723.ppops.net (m0353723.ppops.net [127.0.0.1]) by pps.reinject (8.18.0.8/8.18.0.8) with ESMTP id 46O9cliA003049; Wed, 24 Jul 2024 09:43:00 GMT Received: from ppma21.wdc07v.mail.ibm.com (5b.69.3da9.ip4.static.sl-reverse.com [169.61.105.91]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 40jxjr03ag-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 24 Jul 2024 09:43:00 +0000 (GMT) Received: from pps.filterd (ppma21.wdc07v.mail.ibm.com [127.0.0.1]) by ppma21.wdc07v.mail.ibm.com (8.17.1.19/8.17.1.19) with ESMTP id 46O60aR4006472; Wed, 24 Jul 2024 09:42:59 GMT Received: from smtprelay06.dal12v.mail.ibm.com ([172.16.1.8]) by ppma21.wdc07v.mail.ibm.com (PPS) with ESMTPS id 40gxn7ewvk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 24 Jul 2024 09:42:59 +0000 Received: from smtpav04.wdc07v.mail.ibm.com (smtpav04.wdc07v.mail.ibm.com [10.39.53.231]) by smtprelay06.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 46O9guIO32375450 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 24 Jul 2024 09:42:58 GMT Received: from smtpav04.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0B83A5805E; Wed, 24 Jul 2024 09:42:56 +0000 (GMT) Received: from smtpav04.wdc07v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F2C9858050; Wed, 24 Jul 2024 09:42:50 +0000 (GMT) Received: from [9.43.61.11] (unknown [9.43.61.11]) by smtpav04.wdc07v.mail.ibm.com (Postfix) with ESMTP; Wed, 24 Jul 2024 09:42:50 +0000 (GMT) Message-ID: <09cd33fa-3167-4b74-9559-5624b375b8cf@linux.ibm.com> Date: Wed, 24 Jul 2024 15:12:49 +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] lmprove loop_unroll_adjust X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: Gmc1vrgN-NSQpemSXPsCQxLKOj8I8Wg6 X-Proofpoint-GUID: VPI9Qdln5-nJXsLzmTEbqNoirlh4sOqL 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-24_07,2024-07-23_02,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 clxscore=1015 impostorscore=0 suspectscore=0 mlxscore=0 bulkscore=0 priorityscore=1501 malwarescore=0 phishscore=0 mlxlogscore=710 lowpriorityscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2407110000 definitions=main-2407240069 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 improves loop_unroll_adjust by adding mem count to calculate unroll factor. Bootstrapped and regtested on powerpc64-linux-gnu. Thanks & Regards Ajit rs6000: Improve loop_unroll_adjust Improves loop_unroll_adjust by adding mem count to calculate unroll factor. 2024-07-24 Ajit Kumar Agarwal gcc/ChangeLog: * config/rs6000/rs6000.cc: Improve loop_unroll_adjust by adding mem count to calculate unroll factor. --- gcc/config/rs6000/rs6000.cc | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc index 0bcc6a2d0ab..3dd3857a74e 100644 --- a/gcc/config/rs6000/rs6000.cc +++ b/gcc/config/rs6000/rs6000.cc @@ -81,6 +81,7 @@ #include "ppc-auxv.h" #include "rs6000-internal.h" #include "opts.h" +#include "rtl-iter.h" /* This file should be included last. */ #include "target-def.h" @@ -5570,7 +5571,11 @@ rs6000_cost_data::finish_cost (const vector_costs *scalar_costs) static unsigned rs6000_loop_unroll_adjust (unsigned nunroll, struct loop *loop) { - if (unroll_only_small_loops) + basic_block *bbs; + rtx_insn *insn; + unsigned i; + unsigned mem_count = 0; + if (unroll_only_small_loops) { /* TODO: These are hardcoded values right now. We probably should use a PARAM here. */ @@ -5582,6 +5587,28 @@ rs6000_loop_unroll_adjust (unsigned nunroll, struct loop *loop) return 0; } + /* Count the number of memory references within the loop body. */ + subrtx_iterator::array_type array; + bbs = get_loop_body (loop); + for (i = 0; i < loop->num_nodes; i++) + FOR_BB_INSNS (bbs[i], insn) + if (NONDEBUG_INSN_P (insn)) + FOR_EACH_SUBRTX (iter, array, PATTERN (insn), NONCONST) + if (const_rtx x = *iter) + if (MEM_P (x)) + { + machine_mode mode = GET_MODE (x); + unsigned int n_words = GET_MODE_SIZE (mode) / UNITS_PER_WORD; + if (n_words > 4) + mem_count += 2; + else + mem_count += 1; + } + free (bbs); + + if (mem_count && mem_count <=32) + return MIN (nunroll, 32 / mem_count); + return nunroll; }