public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Guenther <rguenther@suse.de>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] Back to forward-scan for combine in forwprop
Date: Fri, 10 Jun 2011 11:41:00 -0000	[thread overview]
Message-ID: <alpine.LNX.2.00.1106101330540.810@zhemvz.fhfr.qr> (raw)


Dunno why I thought a backward scan was preferable (it would scan
inserted stmts), but it clearly is better to first visit the
defs of the uses of stmts we are trying to combine.  The following
patch uses some trick to make sure stmts inserted by the combining
are processed as well.

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

Richard.

2011-06-10  Richard Guenther  <rguenther@suse.de>

	* tree-ssa-forwprop.c (ssa_forward_propagate_and_combine):
	Scan stmts forward when combining, visit inserted stmts when
	a stmt was changed.

Index: gcc/tree-ssa-forwprop.c
===================================================================
--- gcc/tree-ssa-forwprop.c	(revision 174841)
+++ gcc/tree-ssa-forwprop.c	(working copy)
@@ -2212,7 +2212,8 @@ ssa_forward_propagate_and_combine (void)
 
   FOR_EACH_BB (bb)
     {
-      gimple_stmt_iterator gsi;
+      gimple_stmt_iterator gsi, prev;
+      bool prev_initialized;
 
       /* Apply forward propagation to all stmts in the basic-block.
 	 Note we update GSI within the loop as necessary.  */
@@ -2304,7 +2305,8 @@ ssa_forward_propagate_and_combine (void)
 
       /* Combine stmts with the stmts defining their operands.
 	 Note we update GSI within the loop as necessary.  */
-      for (gsi = gsi_last_bb (bb); !gsi_end_p (gsi);)
+      prev_initialized = false;
+      for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi);)
 	{
 	  gimple stmt = gsi_stmt (gsi);
 	  bool changed = false;
@@ -2386,9 +2388,24 @@ ssa_forward_propagate_and_combine (void)
 	    default:;
 	    }
 
-	  /* If the stmt changed try combining it again.  */
-	  if (!changed)
-	    gsi_prev (&gsi);
+	  if (changed)
+	    {
+	      /* If the stmt changed then re-visit it and the statements
+		 inserted before it.  */
+	      if (!prev_initialized)
+		gsi = gsi_start_bb (bb);
+	      else
+		{
+		  gsi = prev;
+		  gsi_next (&gsi);
+		}
+	    }
+	  else
+	    {
+	      prev = gsi;
+	      prev_initialized = true;
+	      gsi_next (&gsi);
+	    }
 	}
     }
 

                 reply	other threads:[~2011-06-10 11: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=alpine.LNX.2.00.1106101330540.810@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).