From patchwork Sun Jul 7 08:30:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 1957663 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=emGZQfid; dkim=pass (2048-bit key; unprotected) header.d=wanadoo.fr header.i=@wanadoo.fr header.a=rsa-sha256 header.s=t20230301 header.b=hGEi/n62; 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 4WH0pH2gLMz1xr7 for ; Sun, 7 Jul 2024 18:31:17 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 64FF9385B50D for ; Sun, 7 Jul 2024 08:31:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 64FF9385B50D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1720341074; bh=TE+fUUauTujlo6gjziHH0R/Ep2A7IKxRECEn5iFYjWw=; h=From:To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=emGZQfidMAHv1OG70FoCW2EvPuKUeu0MS6pKO/VLDiBodInBBufL3Olc0L0NU4a3H 20gcHBEQojB7L+hI7nsWkBgTgLFemCnh8uQwHxGqoaNhsYPZXiyMl3uQiDEQVxvMLs unT2MeywFLqofcT8xBeJX/eibB3lU6uhjbWaPf68= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from out.smtpout.orange.fr (out-18.smtpout.orange.fr [193.252.22.18]) by sourceware.org (Postfix) with ESMTPS id A648C3858CDA; Sun, 7 Jul 2024 08:30:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org A648C3858CDA Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=gcc.gnu.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org A648C3858CDA Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=193.252.22.18 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720341035; cv=none; b=JU/r3Y1PxyewPDR4ML64G1oz0iUPge8zydeH9yZ8dKHWecwWkhOz64UvyLJP+0C66Lubk57N+OJlUr9V4FV0qnboWT2FgrOFrQjqGOY48KigeWbZYqhGpKz838vBjLoe7vHXEsQ9ZvtrDKveU7xmnTR3WosWO+RJ+QHTxsOSHIs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720341035; c=relaxed/simple; bh=elIeIxr8MSGe/oxZXlf/bMm7KIWTPZWd5aennJMFEsk=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=kQcObgZynL7TOGAJU3fdddE/WURxU2mfp1EN0Y6ftbNkD0ESqDi0qWSGhpKlG/3DpwvmdFrbclT4ztGIMLp4jq5UZJ7NleA+YdTcUZ8OLMdFAZarU4nrVQs8t8OO9MXjsD76l0Id81x6I3f1HzOQ8Voitr3Sq/hQZrYUQPNz4LE= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from cyrano.home ([86.215.161.51]) by smtp.orange.fr with ESMTPA id QNHnse184TXauQNHusdjNT; Sun, 07 Jul 2024 10:30:28 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=wanadoo.fr; s=t20230301; t=1720341028; bh=TE+fUUauTujlo6gjziHH0R/Ep2A7IKxRECEn5iFYjWw=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=hGEi/n62Qw3MHM8d3sKNKIkHtZt2ziM6KLbMp9MgbgTdJa8R9VVImk3Q6OgcBrxO/ it/kf+lDXmm4igJrK/Oe268tbmOXOkikMjsnW4lVF8rKV7A0VONYMa4j6ibTui/LJd JSMpcbE9LDBjXLhfvPOGRr0bjO7RPSip8H0WaRgKCWiCAMAo6xpj6EBI23U/aIpkIN 2I+4nnj8SgUVIu7uVmUpDV3cVIWK/8BQJTUh303jDDK8/MBj8B99J1RPgKSA0kgTy7 8h2qQLUobgHjXvfNmaBVrSZ1sQMtLGOOzywdL38stUi+vP9MybZd/riSYcM50ibDI+ 3AJGAvC0G/2Xg== X-ME-Helo: cyrano.home X-ME-Auth: bW9yaW4tbWlrYWVsQG9yYW5nZS5mcg== X-ME-Date: Sun, 07 Jul 2024 10:30:28 +0200 X-ME-IP: 86.215.161.51 From: Mikael Morin To: gcc-patches@gcc.gnu.org Cc: Mikael Morin Subject: [PATCH] fortran: Move definition of variable closer to its uses Date: Sun, 7 Jul 2024 10:30:13 +0200 Message-ID: <20240707083013.673838-1-mikael@gcc.gnu.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, FORGED_SPF_HELO, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_NEUTRAL, 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, I have found this small cleanup lying in a local branch. Regression-tested on x86_64-linux, OK for master? -- 8< -- No change of behaviour, this makes a variable easier to track. gcc/fortran/ChangeLog: * trans-array.cc (gfc_trans_preloop_setup): Use a separate variable for iteration. Use directly the value of variable I if it is known. Move the definition of the variable to the branch where the remaining uses are. --- gcc/fortran/trans-array.cc | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc index 510f429ef8e..c34c97257a9 100644 --- a/gcc/fortran/trans-array.cc +++ b/gcc/fortran/trans-array.cc @@ -4294,7 +4294,6 @@ gfc_trans_preloop_setup (gfc_loopinfo * loop, int dim, int flag, gfc_ss *ss, *pss; gfc_loopinfo *ploop; gfc_array_ref *ar; - int i; /* This code will be executed before entering the scalarization loop for this dimension. */ @@ -4340,19 +4339,10 @@ gfc_trans_preloop_setup (gfc_loopinfo * loop, int dim, int flag, pss = ss; } - if (dim == loop->dimen - 1) - i = 0; - else - i = dim + 1; - - /* For the time being, there is no loop reordering. */ - gcc_assert (i == ploop->order[i]); - i = ploop->order[i]; - if (dim == loop->dimen - 1 && loop->parent == NULL) { stride = gfc_conv_array_stride (info->descriptor, - innermost_ss (ss)->dim[i]); + innermost_ss (ss)->dim[0]); /* Calculate the stride of the innermost loop. Hopefully this will allow the backend optimizers to do their stuff more effectively. @@ -4364,7 +4354,7 @@ gfc_trans_preloop_setup (gfc_loopinfo * loop, int dim, int flag, base offset of the array. */ if (info->ref) { - for (i = 0; i < ar->dimen; i++) + for (int i = 0; i < ar->dimen; i++) { if (ar->dimen_type[i] != DIMEN_ELEMENT) continue; @@ -4374,8 +4364,21 @@ gfc_trans_preloop_setup (gfc_loopinfo * loop, int dim, int flag, } } else - /* Add the offset for the previous loop dimension. */ - add_array_offset (pblock, ploop, ss, ar, pss->dim[i], i); + { + int i; + + if (dim == loop->dimen - 1) + i = 0; + else + i = dim + 1; + + /* For the time being, there is no loop reordering. */ + gcc_assert (i == ploop->order[i]); + i = ploop->order[i]; + + /* Add the offset for the previous loop dimension. */ + add_array_offset (pblock, ploop, ss, ar, pss->dim[i], i); + } /* Remember this offset for the second loop. */ if (dim == loop->temp_dim - 1 && loop->parent == NULL)