public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Zhenqiang Chen <zhenqiang.chen@linaro.org>
To: gcc-patches@gcc.gnu.org
Subject: [PATCH] Enhance shrink-wrap
Date: Thu, 06 Jun 2013 09:55:00 -0000	[thread overview]
Message-ID: <CACgzC7Dyrc4Zc=WDKy=m03Wwp3hmrgD315b5vRuV9_gO_4MA-A@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 1044 bytes --]

Hi,

The patch enhance prepare_shrink_wrap by doing copyprop for the entry
block.  This exposes more opportunities for shrink-wrapping.  These
kinds of copies often occur when incoming argument registers are moved
to call-saved registers because their values are live across one or
more calls during the function.

* For SPECint2000 (-O3), the number of functions, which can be
shrink-wrapped, increase from 197 to 364 on ARM and from 364 to 618 on
X86-64 with the patch.
* No SPECint2000 performance regression for X86-64 and ARM.
* On X86-64 (-O3), 253.perlbmk is ~3% better.
* On ARM (A15, -O3), 453.povray is ~5% better.
* Bootstrapped and no make check regression for X86-64 and ARM A9.

Is it OK for trunk?

Thanks!
-Zhenqiang

ChangeLog:
2013-06-06  Zhenqiang Chen  <zhenqiang.chen@linaro.org>

	* function.c (prepare_shrink_wrap): Do copy prop for entry block.
	* function.h (copyprop_hardreg_forward_blocks): New.
	* regcprop.c (copyprop_hardreg_forward_blocks): New.
	(copyprop_hardreg_forward): Call copyprop_hardreg_forward_blocks.

[-- Attachment #2: Enhance-shrink-wrap.patch --]
[-- Type: application/octet-stream, Size: 3565 bytes --]

diff --git a/gcc/function.c b/gcc/function.c
index 36c874f..1a50ec9 100644
--- a/gcc/function.c
+++ b/gcc/function.c
@@ -5563,9 +5563,15 @@ prepare_shrink_wrap (basic_block entry_block)
   rtx insn, curr, x;
   HARD_REG_SET uses, defs;
   df_ref *ref;
+  rtx jump = BB_END (entry_block);
 
   CLEAR_HARD_REG_SET (uses);
   CLEAR_HARD_REG_SET (defs);
+
+  /* Do copy propagation for the entry block.  */
+  if (JUMP_P (jump))
+    copyprop_hardreg_forward_blocks (true);
+
   FOR_BB_INSNS_REVERSE_SAFE (entry_block, insn, curr)
     if (NONDEBUG_INSN_P (insn)
 	&& !move_insn_for_shrink_wrap (entry_block, insn, uses, defs))
diff --git a/gcc/function.h b/gcc/function.h
index c651f50..d14ea27 100644
--- a/gcc/function.h
+++ b/gcc/function.h
@@ -791,6 +791,7 @@ extern int get_last_funcdef_no (void);
 
 #ifdef HAVE_simple_return
 extern bool requires_stack_frame_p (rtx, HARD_REG_SET, HARD_REG_SET);
+extern unsigned int copyprop_hardreg_forward_blocks (bool entry_block_only);
 #endif                        
 
 extern rtx get_hard_reg_initial_val (enum machine_mode, unsigned int);
diff --git a/gcc/regcprop.c b/gcc/regcprop.c
index 896902f..127ee82 100644
--- a/gcc/regcprop.c
+++ b/gcc/regcprop.c
@@ -1038,10 +1038,11 @@ copyprop_hardreg_forward_1 (basic_block bb, struct value_data *vd)
   return anything_changed;
 }
 
-/* Main entry point for the forward copy propagation optimization.  */
+/* If ENTRY_BLOCK_ONLY is TRUE, it only progagates the first basic block.
+   Shrink-wrap uses it to optimize copies from arguments.  */
 
-static unsigned int
-copyprop_hardreg_forward (void)
+unsigned int
+copyprop_hardreg_forward_blocks (bool entry_block_only)
 {
   struct value_data *all_vd;
   basic_block bb;
@@ -1090,32 +1091,38 @@ copyprop_hardreg_forward (void)
 	init_value_data (all_vd + bb->index);
 
       copyprop_hardreg_forward_1 (bb, all_vd + bb->index);
+
+      if (entry_block_only) break;
     }
 
   if (MAY_HAVE_DEBUG_INSNS)
     {
       FOR_EACH_BB (bb)
-	if (bitmap_bit_p (visited, bb->index)
-	    && all_vd[bb->index].n_debug_insn_changes)
-	  {
-	    unsigned int regno;
-	    bitmap live;
+	{
+	  if (bitmap_bit_p (visited, bb->index)
+	      && all_vd[bb->index].n_debug_insn_changes)
+	    {
+	      unsigned int regno;
+	      bitmap live;
 
-	    if (!analyze_called)
-	      {
-		df_analyze ();
-		analyze_called = true;
-	      }
-	    live = df_get_live_out (bb);
-	    for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
-	      if (all_vd[bb->index].e[regno].debug_insn_changes)
+	      if (!analyze_called)
 		{
-		  if (REGNO_REG_SET_P (live, regno))
-		    apply_debug_insn_changes (all_vd + bb->index, regno);
-		  if (all_vd[bb->index].n_debug_insn_changes == 0)
-		    break;
+		  df_analyze ();
+		  analyze_called = true;
 		}
-	  }
+	      live = df_get_live_out (bb);
+	      for (regno = 0; regno < FIRST_PSEUDO_REGISTER; regno++)
+		if (all_vd[bb->index].e[regno].debug_insn_changes)
+		  {
+		    if (REGNO_REG_SET_P (live, regno))
+		      apply_debug_insn_changes (all_vd + bb->index, regno);
+		    if (all_vd[bb->index].n_debug_insn_changes == 0)
+		      break;
+		  }
+	    }
+
+	  if (entry_block_only) break;
+	}
 
       free_alloc_pool (debug_insn_changes_pool);
     }
@@ -1125,6 +1132,14 @@ copyprop_hardreg_forward (void)
   return 0;
 }
 
+/* Main entry point for the forward copy propagation optimization.  */
+
+static unsigned int
+copyprop_hardreg_forward (void)
+{
+   return copyprop_hardreg_forward_blocks (false);
+}
+
 /* Dump the value chain data to stderr.  */
 
 DEBUG_FUNCTION void

             reply	other threads:[~2013-06-06  9:55 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-06  9:55 Zhenqiang Chen [this message]
2013-06-06 12:44 ` Steven Bosscher

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='CACgzC7Dyrc4Zc=WDKy=m03Wwp3hmrgD315b5vRuV9_gO_4MA-A@mail.gmail.com' \
    --to=zhenqiang.chen@linaro.org \
    --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).