From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1314) id EC6AF3858289; Mon, 24 Apr 2023 15:50:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EC6AF3858289 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682351446; bh=pWRUT6qD9iua4cN6grK5IyI8noTfZKs/g+FyzhLKpX4=; h=From:To:Subject:Date:From; b=bLTS5K01oBb/iJpb3WiBTfBTKt6e98AR7pOpEtAASJJ8Lg+6MQZP+wjpjO8kIw0SI l/VBoAhMwIB4AFgCOjbjoLdqQdgBkknTplEYUzgK/aPEdPGy2M3s7eZZtNf+v2bgCv S5kuOvosxZN1kRgDV6ICB7KzOzMv2lR9BVtYlJyY= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Andrew Pinski To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-203] PHIOPT: Ignore predicates for match-and-simplify phi-opt X-Act-Checkin: gcc X-Git-Author: Andrew Pinski X-Git-Refname: refs/heads/trunk X-Git-Oldrev: 245753249c595af95a811ddb0fe572d93a5dae72 X-Git-Newrev: a2339e0fe9dbefdeca49a8105c7a547231c02d34 Message-Id: <20230424155046.EC6AF3858289@sourceware.org> Date: Mon, 24 Apr 2023 15:50:46 +0000 (GMT) List-Id: https://gcc.gnu.org/g:a2339e0fe9dbefdeca49a8105c7a547231c02d34 commit r14-203-ga2339e0fe9dbefdeca49a8105c7a547231c02d34 Author: Andrew Pinski Date: Sun Apr 9 22:47:50 2023 +0000 PHIOPT: Ignore predicates for match-and-simplify phi-opt This fixes a missed optimization where early phi-opt would not work when there was predicates. The easiest fix is to change empty_bb_or_one_feeding_into_p to ignore those statements while checking for only feeding statement. Note phi-opt-23.c and phi-opt-24.c still fail as we don't handle diamond form in match_and_simplify phiopt yet. OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * tree-ssa-phiopt.cc (empty_bb_or_one_feeding_into_p): Instead of calling last_and_only_stmt, look for the last statement manually. gcc/testsuite/ChangeLog: * gcc.dg/tree-ssa/ssa-ifcombine-13.c: Add -fno-ssa-phiopt. Diff: --- gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-13.c | 4 +++- gcc/tree-ssa-phiopt.cc | 22 ++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-13.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-13.c index 425eb3d6481..7976544c79b 100644 --- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-13.c +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-ifcombine-13.c @@ -1,5 +1,7 @@ /* { dg-do compile } */ -/* { dg-options "-O1 -fdump-tree-optimized-details-blocks --param logical-op-non-short-circuit=1" } */ +/* Disable phi-opt as it is no longer confused by predicate which had allowed ifcombine to work in the past. + Note this testcase is about ifcombine rather than phi-opt. */ +/* { dg-options "-O1 -fdump-tree-optimized-details-blocks --param logical-op-non-short-circuit=1 -fno-ssa-phiopt" } */ _Bool f1(_Bool a, _Bool b) { diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc index f3164b8511b..f17c3507d11 100644 --- a/gcc/tree-ssa-phiopt.cc +++ b/gcc/tree-ssa-phiopt.cc @@ -960,9 +960,27 @@ empty_bb_or_one_feeding_into_p (basic_block bb, if (!gimple_seq_empty_p (phi_nodes (bb))) return false; - stmt_to_move = last_and_only_stmt (bb); + gimple_stmt_iterator gsi; + + gsi = gsi_start_nondebug_after_labels_bb (bb); + while (!gsi_end_p (gsi)) + { + gimple *s = gsi_stmt (gsi); + gsi_next_nondebug (&gsi); + /* Skip over Predict and nop statements. */ + if (gimple_code (s) == GIMPLE_PREDICT + || gimple_code (s) == GIMPLE_NOP) + continue; + /* If there is more one statement return false. */ + if (stmt_to_move) + return false; + stmt_to_move = s; + } + + /* The only statement here was a Predict or a nop statement + so return true. */ if (!stmt_to_move) - return false; + return true; if (gimple_vuse (stmt_to_move)) return false;