Patchwork [5/6] Generate more shrink-wrapping opportunities

login
register
mail settings
Submitter Bernd Schmidt
Date March 31, 2011, 1:29 p.m.
Message ID <4D9481BC.8030809@codesourcery.com>
Download mbox | patch
Permalink /patch/89076/
State New
Headers show

Comments

Bernd Schmidt - March 31, 2011, 1:29 p.m.
On 03/31/2011 03:23 PM, Jeff Law wrote:
> On 03/23/11 08:55, Bernd Schmidt wrote:
>> The first basic block contains insns to move incoming argument registers
>> to pseudos. When these pseudos live across calls, they get allocated to
>> call-saved registers. This in turns disables shrink-wrapping, since the
>> move instruction requires the prologue (saving the call-saved reg) to
>> occur before it.
> 
>> This patch addresses the problem by moving such moves downwards through
>> the CFG until we find a place where the destination is used or the
>> incoming argument is clobbered.
> OK.

Thanks for the reviews. This patch is still blocked by the issues raised
by rth in 3/6 (and of course the full shrink-wrapping patch 4/6); I hope
to have at least draft patches for the dwarf2out problems by the end of
the week.

We've also discovered a problem with this particular patch, it requires
the additional fix posted below which I'll include in an eventual commit.

> At some point I'll probably want to move this code to run
> immediately after IRA completes and extend it in a few ways, but for now
> it's OK as it stands.

Note that the prepare_shrink_wrap code can be further enhanced by
running a regcprop pass before thread_prologue_and_epilogue_insns, since
that tends to eliminate uses of the call-used destination reg. I'm going
to submit a patch for this once all the other shrink-wrapping bits are in.


Bernd

Patch

Index: function.c
===================================================================
--- function.c	(revision 318184)
+++ function.c	(working copy)
@@ -5190,6 +5190,23 @@  emit_return_into_block (bool simple_p, b
 }
 #endif
 
+/* Return true if BB has any active insns.  */
+static bool
+bb_active_p (basic_block bb)
+{
+  rtx label;
+
+  /* Test whether there are active instructions in the last block.  */
+  label = BB_END (bb);
+  while (label && !LABEL_P (label))
+    {
+      if (active_insn_p (label))
+	break;
+      label = PREV_INSN (label);
+    }
+  return BB_HEAD (bb) != label || !LABEL_P (label);
+}
+
 /* Generate the prologue and epilogue RTL if the machine supports it.  Thread
    this into place with notes indicating where the prologue ends and where
    the epilogue begins.  Update the basic block information when possible.
@@ -5275,19 +5292,8 @@  thread_prologue_and_epilogue_insns (void
   exit_fallthru_edge = find_fallthru_edge (EXIT_BLOCK_PTR->preds);
   if (exit_fallthru_edge != NULL)
     {
-      rtx label;
-
       last_bb = exit_fallthru_edge->src;
-      /* Test whether there are active instructions in the last block.  */
-      label = BB_END (last_bb);
-      while (label && !LABEL_P (label))
-	{
-	  if (active_insn_p (label))
-	    break;
-	  label = PREV_INSN (label);
-	}
-
-      last_bb_active = BB_HEAD (last_bb) != label || !LABEL_P (label);
+      last_bb_active = bb_active_p (last_bb);
     }
   else
     {
@@ -5344,6 +5350,10 @@  thread_prologue_and_epilogue_insns (void
 
       prepare_shrink_wrap (entry_edge->dest);
 
+      /* That may have inserted instructions into the last block.  */
+      if (last_bb && !last_bb_active)
+	last_bb_active = bb_active_p (last_bb);
+
       bitmap_initialize (&bb_antic_flags, &bitmap_default_obstack);
       bitmap_initialize (&bb_on_list, &bitmap_default_obstack);