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] Fix PR80842
Date: Fri, 26 May 2017 07:54:00 -0000	[thread overview]
Message-ID: <alpine.LSU.2.20.1705260915270.20726@zhemvz.fhfr.qr> (raw)


There's quite some instability in the lattice when match-and-simplify
is mixed with CCP.  We deal with part of that already by meeting
with the old value in set_lattice_value, the following deals with this
new case by doing it always.

SSA propagation and match-and-simplify don't play well with each
other, a solution would be to forgo with that and use a simpler
iteration scheme.

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

Richard.

2017-05-26  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/80842
	* tree-ssa-ccp.c (set_lattice_value): Always meet with the old
	value.

	* gcc.dg/torture/pr80842.c: New testcase.

Index: gcc/tree-ssa-ccp.c
===================================================================
--- gcc/tree-ssa-ccp.c	(revision 248409)
+++ gcc/tree-ssa-ccp.c	(working copy)
@@ -497,9 +497,7 @@ set_lattice_value (tree var, ccp_prop_va
      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 (new_val->lattice_val == CONSTANT
-      && old_val->lattice_val == CONSTANT
-      && TREE_CODE (new_val->value) != SSA_NAME)
+  if (old_val->lattice_val != UNINITIALIZED)
     ccp_lattice_meet (new_val, old_val);
 
   gcc_checking_assert (valid_lattice_transition (*old_val, *new_val));
Index: gcc/testsuite/gcc.dg/torture/pr80842.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr80842.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/torture/pr80842.c	(working copy)
@@ -0,0 +1,23 @@
+/* { dg-do compile } */
+
+unsigned a;
+short b;
+char c, d, e;
+void fn1();
+void fn2() {
+    a++;
+    for (; a;)
+      fn1(0, 0);
+}
+void fn3() {
+    fn2();
+l1:;
+   unsigned char f;
+   short g;
+   unsigned char *h = &f;
+   g += &h ? e ? g = 1 : 0 : 0;
+   d = g;
+   c *f;
+   if (d & (b %= *h) < f * d / (d -= 0))
+     goto l1;
+}

                 reply	other threads:[~2017-05-26  7:17 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=alpine.LSU.2.20.1705260915270.20726@zhemvz.fhfr.qr \
    --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).