public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-5348] tree-optimization/108523 - fix endless iteration in VN
Date: Wed, 25 Jan 2023 12:37:39 +0000 (GMT)	[thread overview]
Message-ID: <20230125123739.EC17F3858C53@sourceware.org> (raw)

https://gcc.gnu.org/g:c29d85359add807200a1a851026b4e4a9d6b714c

commit r13-5348-gc29d85359add807200a1a851026b4e4a9d6b714c
Author: Richard Biener <rguenther@suse.de>
Date:   Wed Jan 25 13:31:46 2023 +0100

    tree-optimization/108523 - fix endless iteration in VN
    
    The following fixes not converging iteration in value-numbering of
    PHI nodes when we use an equivalence to prove the PHI node is
    degenerate.  We have to avoid the situation where we oscillate
    between the two equivalent values because the result is fed back
    via a backedge.
    
            PR tree-optimization/108523
            * tree-ssa-sccvn.cc (visit_phi): Avoid using the exclusive
            backedge value for the result when using predication to
            prove equivalence.

Diff:
---
 gcc/tree-ssa-sccvn.cc | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/gcc/tree-ssa-sccvn.cc b/gcc/tree-ssa-sccvn.cc
index 0dba3f39aa0..edb553b07cb 100644
--- a/gcc/tree-ssa-sccvn.cc
+++ b/gcc/tree-ssa-sccvn.cc
@@ -5826,7 +5826,7 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p)
   poly_int64 soff, doff;
   unsigned n_executable = 0;
   edge_iterator ei;
-  edge e;
+  edge e, sameval_e = NULL;
 
   /* TODO: We could check for this in initialization, and replace this
      with a gcc_assert.  */
@@ -5867,7 +5867,10 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p)
 		 && ssa_undefined_value_p (def, false))
 	  seen_undef = def;
 	else if (sameval == VN_TOP)
-	  sameval = def;
+	  {
+	    sameval = def;
+	    sameval_e = e;
+	  }
 	else if (!expressions_equal_p (def, sameval))
 	  {
 	    /* We know we're arriving only with invariant addresses here,
@@ -5916,6 +5919,8 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p)
 			    fprintf (dump_file, " are equal on edge %d -> %d\n",
 				     e->src->index, e->dest->index);
 			  }
+			if (sameval_e && (sameval_e->flags & EDGE_DFS_BACK))
+			  sameval = def;
 			continue;
 		      }
 		    /* If on all previous edges the value was equal to def
@@ -5935,7 +5940,8 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p)
 				     EDGE_PRED (bb, 0)->src->index,
 				     EDGE_PRED (bb, 0)->dest->index);
 			  }
-			sameval = def;
+			if (!(e->flags & EDGE_DFS_BACK))
+			  sameval = def;
 			continue;
 		      }
 		  }
@@ -5943,6 +5949,8 @@ visit_phi (gimple *phi, bool *inserted, bool backedges_varying_p)
 	    sameval = NULL_TREE;
 	    break;
 	  }
+	else
+	  sameval_e = NULL;
       }
 
   /* If the value we want to use is flowing over the backedge and we

                 reply	other threads:[~2023-01-25 12:37 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=20230125123739.EC17F3858C53@sourceware.org \
    --to=rguenth@gcc.gnu.org \
    --cc=gcc-cvs@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).