From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 5854C3858D38; Thu, 10 Nov 2022 13:13:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5854C3858D38 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668085985; bh=4mVKizNoyW0fOJVM1DMyNKnkaiaJMomrvJ5ymmqMEhI=; h=From:To:Subject:Date:From; b=svz2sO/V6B2HdL3vf2zLA5lqzsAbHgcPhFUiZhcy60fJkYjyA/N/3XWfvKfZUkz8O 2MGMzcqfMvrmuULduGTWqP2Gnr1K/ijJuQX+aB+8IeYLXLJ8+707SZC17SlLRYr/IK nL0RFl5MC9Ca0K/aTWzQm369nvMnnfJ/m2OA6xAo= 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 r13-3877] Restore CCP copy propagation X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/master X-Git-Oldrev: bd044dae51caea3c641f86ec5cb0ebccf7e06de7 X-Git-Newrev: 203b127fccc9abe5373c9e3cc03a476c35b1f594 Message-Id: <20221110131305.5854C3858D38@sourceware.org> Date: Thu, 10 Nov 2022 13:13:05 +0000 (GMT) List-Id: https://gcc.gnu.org/g:203b127fccc9abe5373c9e3cc03a476c35b1f594 commit r13-3877-g203b127fccc9abe5373c9e3cc03a476c35b1f594 Author: Richard Biener Date: Thu Nov 10 14:08:35 2022 +0100 Restore CCP copy propagation The following restores copy propagation in CCP for the case the lattice was constant before trying to transition to a copy. At some point we changed to use the meet operator to handle integer constant -> integer constant transitions but that screws up the const -> copy lattice transition. PR tree-optimization/84646 * tree-ssa-ccp.cc (set_lattice_value): Make sure we allow a const -> copy transition and avoid using meet in that case. * gcc.dg/tree-ssa/ssa-ccp-42.c: New testcase. Diff: --- gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-42.c | 26 ++++++++++++++++++++++++++ gcc/tree-ssa-ccp.cc | 7 ++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-42.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-42.c new file mode 100644 index 00000000000..b4e5c0f73f2 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-42.c @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-options "-fgimple -O -fdump-tree-ccp1" } */ + +__GIMPLE (ssa,startwith("ccp")) int foo (int n) +{ + int i; + int j; + + __BB(2): + i_1 = 0; + goto __BB3; + + __BB(3): + i_2 = __PHI (__BB2: i_1, __BB3: i_4); + j_3 = i_2; + i_4 = i_2 + 1; + if (i_4 < n_5(D)) + goto __BB3; + else + goto __BB4; + + __BB(4): + return j_3; +} + +/* { dg-final { scan-tree-dump "return i_2;" "ccp1" } } */ diff --git a/gcc/tree-ssa-ccp.cc b/gcc/tree-ssa-ccp.cc index 2bcd90646f6..69fd7f1d11d 100644 --- a/gcc/tree-ssa-ccp.cc +++ b/gcc/tree-ssa-ccp.cc @@ -532,7 +532,12 @@ set_lattice_value (tree var, ccp_prop_value_t *new_val) use the meet operator to retain a conservative value. Missed optimizations like PR65851 makes this necessary. It also ensures we converge to a stable lattice solution. */ - if (old_val->lattice_val != UNINITIALIZED) + if (old_val->lattice_val != UNINITIALIZED + /* But avoid using meet for constant -> copy transitions. */ + && !(old_val->lattice_val == CONSTANT + && CONSTANT_CLASS_P (old_val->value) + && new_val->lattice_val == CONSTANT + && TREE_CODE (new_val->value) == SSA_NAME)) ccp_lattice_meet (new_val, old_val); gcc_checking_assert (valid_lattice_transition (*old_val, *new_val));