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 problem reported in PR68465
Date: Mon, 23 Nov 2015 15:22:00 -0000	[thread overview]
Message-ID: <alpine.LSU.2.11.1511231615250.4884@t29.fhfr.qr> (raw)


The following fixes CH - FRE - LIM not doing store-motion across a loop
nest for redundant header checks.  FRE is supposed to do such
redundant comparison "threading" but didn't do it because of latch
edges confusing the single_pred_p check.

The following fixes it by disregarding edges that come from blocks
we dominate.

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

Richard.

2015-11-23  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/68465
	* tree-ssa-sccvn.c (sccvn_dom_walker::before_dom_children):
	Also record equalities from multiple predecessor blocks if
	only one non-backedge exists.

	* gcc.dg/tree-ssa/ssa-fre-52.c: New testcase.

Index: gcc/tree-ssa-sccvn.c
===================================================================
*** gcc/tree-ssa-sccvn.c	(revision 230737)
--- gcc/tree-ssa-sccvn.c	(working copy)
*************** sccvn_dom_walker::before_dom_children (b
*** 4357,4376 ****
  
    /* If we have a single predecessor record the equivalence from a
       possible condition on the predecessor edge.  */
!   if (single_pred_p (bb))
      {
-       edge e = single_pred_edge (bb);
        /* Check if there are multiple executable successor edges in
  	 the source block.  Otherwise there is no additional info
  	 to be recorded.  */
        edge e2;
!       FOR_EACH_EDGE (e2, ei, e->src->succs)
! 	if (e2 != e
  	    && e2->flags & EDGE_EXECUTABLE)
  	  break;
        if (e2 && (e2->flags & EDGE_EXECUTABLE))
  	{
! 	  gimple *stmt = last_stmt (e->src);
  	  if (stmt
  	      && gimple_code (stmt) == GIMPLE_COND)
  	    {
--- 4402,4435 ----
  
    /* If we have a single predecessor record the equivalence from a
       possible condition on the predecessor edge.  */
!   edge pred_e = NULL;
!   FOR_EACH_EDGE (e, ei, bb->preds)
!     {
!       /* Ignore simple backedges from this to allow recording conditions
!          in loop headers.  */
!       if (dominated_by_p (CDI_DOMINATORS, e->src, e->dest))
! 	continue;
!       if (! pred_e)
! 	pred_e = e;
!       else
! 	{
! 	  pred_e = NULL;
! 	  break;
! 	}
!     }
!   if (pred_e)
      {
        /* Check if there are multiple executable successor edges in
  	 the source block.  Otherwise there is no additional info
  	 to be recorded.  */
        edge e2;
!       FOR_EACH_EDGE (e2, ei, pred_e->src->succs)
! 	if (e2 != pred_e
  	    && e2->flags & EDGE_EXECUTABLE)
  	  break;
        if (e2 && (e2->flags & EDGE_EXECUTABLE))
  	{
! 	  gimple *stmt = last_stmt (pred_e->src);
  	  if (stmt
  	      && gimple_code (stmt) == GIMPLE_COND)
  	    {
*************** sccvn_dom_walker::before_dom_children (b
*** 4378,4388 ****
  	      tree lhs = gimple_cond_lhs (stmt);
  	      tree rhs = gimple_cond_rhs (stmt);
  	      record_conds (bb, code, lhs, rhs,
! 			    (e->flags & EDGE_TRUE_VALUE) != 0);
  	      code = invert_tree_comparison (code, HONOR_NANS (lhs));
  	      if (code != ERROR_MARK)
  		record_conds (bb, code, lhs, rhs,
! 			      (e->flags & EDGE_TRUE_VALUE) == 0);
  	    }
  	}
      }
--- 4437,4447 ----
  	      tree lhs = gimple_cond_lhs (stmt);
  	      tree rhs = gimple_cond_rhs (stmt);
  	      record_conds (bb, code, lhs, rhs,
! 			    (pred_e->flags & EDGE_TRUE_VALUE) != 0);
  	      code = invert_tree_comparison (code, HONOR_NANS (lhs));
  	      if (code != ERROR_MARK)
  		record_conds (bb, code, lhs, rhs,
! 			      (pred_e->flags & EDGE_TRUE_VALUE) == 0);
  	    }
  	}
      }
Index: gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-52.c
===================================================================
*** gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-52.c	(revision 0)
--- gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-52.c	(working copy)
***************
*** 0 ****
--- 1,26 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O -fdump-tree-fre1" } */
+ 
+ void bar ();
+ void foo (int n)
+ {
+   if (n > 0)
+     {
+       int j = 0;
+       do
+ 	{
+ 	  if (n > 0)
+ 	    {
+ 	      int i = 0;
+ 	      do
+ 		{
+ 		  bar ();
+ 		}
+ 	      while (i < n);
+ 	    }
+ 	}
+       while (j < n);
+     }
+ }
+ 
+ /* { dg-final { scan-tree-dump-times "if" 1 "fre1" } } */

                 reply	other threads:[~2015-11-23 15: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.11.1511231615250.4884@t29.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).