public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] Restore CCP copy propagation
Date: Thu, 10 Nov 2022 14:11:01 +0100 (CET)	[thread overview]
Message-ID: <20221110131102.1091513B58@imap2.suse-dmz.suse.de> (raw)

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.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

	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.
---
 gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-42.c | 26 ++++++++++++++++++++++
 gcc/tree-ssa-ccp.cc                        |  7 +++++-
 2 files changed, 32 insertions(+), 1 deletion(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-ccp-42.c

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));
-- 
2.35.3

                 reply	other threads:[~2022-11-10 13:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221110131102.1091513B58@imap2.suse-dmz.suse.de \
    --to=rguenther@suse.de \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).