From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 7206F3857C5D; Fri, 22 Jul 2022 11:21:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7206F3857C5D MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-10169] tree-optimization/105618 - restore load sinking X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: e2b97d6883a72b0c51dd0455acea43e21b5537d9 X-Git-Newrev: dba0883cbbd0ce7545041be96ae75db1d577affb Message-Id: <20220722112158.7206F3857C5D@sourceware.org> Date: Fri, 22 Jul 2022 11:21:58 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Jul 2022 11:21:58 -0000 https://gcc.gnu.org/g:dba0883cbbd0ce7545041be96ae75db1d577affb commit r11-10169-gdba0883cbbd0ce7545041be96ae75db1d577affb Author: Richard Biener Date: Tue May 17 09:45:02 2022 +0200 tree-optimization/105618 - restore load sinking The PR97330 fix caused some missed sinking of loads out of loops the following patch re-instantiates. 2022-05-17 Richard Biener PR tree-optimization/105618 * tree-ssa-sink.c (statement_sink_location): For virtual PHI uses ignore those defining the used virtual operand. * gcc.dg/tree-ssa/ssa-sink-19.c: New testcase. (cherry picked from commit ebce0e9bd8d714a8607ae24331a3d842b0d11859) Diff: --- gcc/testsuite/gcc.dg/tree-ssa/ssa-sink-19.c | 21 +++++++++++++++++++++ gcc/tree-ssa-sink.c | 3 +++ 2 files changed, 24 insertions(+) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-sink-19.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-sink-19.c new file mode 100644 index 00000000000..f3eb0ef3a4e --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-sink-19.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -fdump-tree-sink-details -fdump-tree-cddce2-details" } */ + +static int b=4; +int c; + +int +main() +{ + int e[5] = {1,1,1,1,1}; + for (; b >= 0; b--) { + c = e[b]; + } + return 0; +} + +/* We should sink e[b] out of the loop which is possible after + applying store motion to c and b. */ +/* { dg-final { scan-tree-dump "Sinking # VUSE" "sink" } } */ +/* And remove the loop after final value replacement. */ +/* { dg-final { scan-tree-dump "fix_loop_structure: removing loop" "cddce2" } } */ diff --git a/gcc/tree-ssa-sink.c b/gcc/tree-ssa-sink.c index 3c2ed795f85..b3097531203 100644 --- a/gcc/tree-ssa-sink.c +++ b/gcc/tree-ssa-sink.c @@ -390,6 +390,9 @@ statement_sink_location (gimple *stmt, basic_block frombb, with the use. */ if (gimple_code (use_stmt) == GIMPLE_PHI) { + /* If the PHI defines the virtual operand, ignore it. */ + if (gimple_phi_result (use_stmt) == gimple_vuse (stmt)) + continue; /* In case the PHI node post-dominates the current insert location we can disregard it. But make sure it is not dominating it as well as can happen in a CFG cycle. */