public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/autopar_devel] tree-optimization/95049 - fix not terminating RPO VN iteration
@ 2020-08-22 21:05 Giuliano Belinassi
  0 siblings, 0 replies; only message in thread
From: Giuliano Belinassi @ 2020-08-22 21:05 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:4ffc2c11eea4f3f32fb211cf0840f3417785cd63

commit 4ffc2c11eea4f3f32fb211cf0840f3417785cd63
Author: Richard Biener <rguenther@suse.de>
Date:   Mon May 11 13:40:37 2020 +0200

    tree-optimization/95049 - fix not terminating RPO VN iteration
    
    This rejects lattice changes from one constant to another.
    
    2020-05-11  Richard Biener  <rguenther@suse.de>
    
            PR tree-optimization/95049
            * tree-ssa-sccvn.c (set_ssa_val_to): Reject lattice transition
            between different constants.
    
            * gcc.dg/torture/pr95049.c: New testcase.

Diff:
---
 gcc/ChangeLog                          |  6 ++++++
 gcc/testsuite/ChangeLog                |  5 +++++
 gcc/testsuite/gcc.dg/torture/pr95049.c |  7 +++++++
 gcc/tree-ssa-sccvn.c                   | 27 ++++++++++++++++++++++-----
 4 files changed, 40 insertions(+), 5 deletions(-)

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index cf6eafd1a15..9ddd08505c8 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2020-05-11  Richard Biener  <rguenther@suse.de>
+
+	PR tree-optimization/95049
+	* tree-ssa-sccvn.c (set_ssa_val_to): Reject lattice transition
+	between different constants.
+
 2020-05-11  Richard Sandiford  <richard.sandiford@arm.com>
 
 	* tree-pretty-print.c (dump_generic_node): Handle BOOLEAN_TYPEs.
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 65feee50c8b..92e1d409304 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2020-05-11  Richard Biener  <rguenther@suse.de>
+
+	PR tree-optimization/95049
+	* gcc.dg/torture/pr95049.c: New testcase.
+
 2020-05-11  Kelvin Nilsen  <kelvin@gcc.gnu.org>
 	    Bill Schmidt  <wschmidt@linux.ibm.com>
 
diff --git a/gcc/testsuite/gcc.dg/torture/pr95049.c b/gcc/testsuite/gcc.dg/torture/pr95049.c
new file mode 100644
index 00000000000..164bfdbdcfc
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr95049.c
@@ -0,0 +1,7 @@
+/* { dg-do compile } */
+
+void a()
+{
+  for (int b; b; b = !b)
+    ;
+}
diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c
index 39e99007c7e..4b3f31c12cb 100644
--- a/gcc/tree-ssa-sccvn.c
+++ b/gcc/tree-ssa-sccvn.c
@@ -4472,6 +4472,8 @@ set_ssa_val_to (tree from, tree to)
   vn_ssa_aux_t from_info = VN_INFO (from);
   tree currval = from_info->valnum; // SSA_VAL (from)
   poly_int64 toff, coff;
+  bool curr_undefined = false;
+  bool curr_invariant = false;
 
   /* The only thing we allow as value numbers are ssa_names
      and invariants.  So assert that here.  We don't allow VN_TOP
@@ -4514,9 +4516,9 @@ set_ssa_val_to (tree from, tree to)
 	    }
 	  return false;
 	}
-      bool curr_invariant = is_gimple_min_invariant (currval);
-      bool curr_undefined = (TREE_CODE (currval) == SSA_NAME
-			     && ssa_undefined_value_p (currval, false));
+      curr_invariant = is_gimple_min_invariant (currval);
+      curr_undefined = (TREE_CODE (currval) == SSA_NAME
+			&& ssa_undefined_value_p (currval, false));
       if (currval != VN_TOP
 	  && !curr_invariant
 	  && !curr_undefined
@@ -4571,9 +4573,8 @@ set_and_exit:
       && !operand_equal_p (currval, to, 0)
       /* Different undefined SSA names are not actually different.  See
          PR82320 for a testcase were we'd otherwise not terminate iteration.  */
-      && !(TREE_CODE (currval) == SSA_NAME
+      && !(curr_undefined
 	   && TREE_CODE (to) == SSA_NAME
-	   && ssa_undefined_value_p (currval, false)
 	   && ssa_undefined_value_p (to, false))
       /* ???  For addresses involving volatile objects or types operand_equal_p
          does not reliably detect ADDR_EXPRs as equal.  We know we are only
@@ -4585,6 +4586,22 @@ set_and_exit:
 	       == get_addr_base_and_unit_offset (TREE_OPERAND (to, 0), &toff))
 	   && known_eq (coff, toff)))
     {
+      if (to != from
+	  && currval != VN_TOP
+	  && !curr_undefined
+	  /* We do not want to allow lattice transitions from one value
+	     to another since that may lead to not terminating iteration
+	     (see PR95049).  Since there's no convenient way to check
+	     for the allowed transition of VAL -> PHI (loop entry value,
+	     same on two PHIs, to same PHI result) we restrict the check
+	     to invariants.  */
+	  && curr_invariant
+	  && is_gimple_min_invariant (to))
+	{
+	  if (dump_file && (dump_flags & TDF_DETAILS))
+	    fprintf (dump_file, " forced VARYING");
+	  to = from;
+	}
       if (dump_file && (dump_flags & TDF_DETAILS))
 	fprintf (dump_file, " (changed)\n");
       from_info->valnum = to;


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-08-22 21:05 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-22 21:05 [gcc/devel/autopar_devel] tree-optimization/95049 - fix not terminating RPO VN iteration Giuliano Belinassi

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).