public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Enhance shrink-wrap
@ 2013-06-06  9:55 Zhenqiang Chen
  2013-06-06 12:44 ` Steven Bosscher
  0 siblings, 1 reply; 2+ messages in thread
From: Zhenqiang Chen @ 2013-06-06  9:55 UTC (permalink / raw)
  To: gcc-patches

[-- 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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Enhance shrink-wrap
  2013-06-06  9:55 [PATCH] Enhance shrink-wrap Zhenqiang Chen
@ 2013-06-06 12:44 ` Steven Bosscher
  0 siblings, 0 replies; 2+ messages in thread
From: Steven Bosscher @ 2013-06-06 12:44 UTC (permalink / raw)
  To: Zhenqiang Chen; +Cc: gcc-patches, Martin Jambor

On Thu, Jun 6, 2013 at 11:55 AM, Zhenqiang Chen wrote:
> 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.

Hello,

This was discussed before, see the thread surrounding:
http://gcc.gnu.org/ml/gcc-patches/2013-04/msg01455.html

This is also http://gcc.gnu.org/PR10474

Ciao!
Steven

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-06-06 12:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-06  9:55 [PATCH] Enhance shrink-wrap Zhenqiang Chen
2013-06-06 12:44 ` Steven Bosscher

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