diff mbox

Initial shrink-wrapping patch

Message ID 4E8C912C.2060805@codesourcery.com
State New
Headers show

Commit Message

Bernd Schmidt Oct. 5, 2011, 5:17 p.m. UTC
On 10/05/11 18:21, Richard Henderson wrote:
> On 10/05/2011 08:59 AM, Bernd Schmidt wrote:
>> Bootstrapping the following now. Ok? (Alternatively, could keep the
>> redzone logic, but make it depend on !flag_shrink_wrap).
> 
> It's a good space-saving optimization, that redzone logic.  We
> should be able to keep it based on crtl->shrink_wrapped; that
> does appear to get set before we actually emit the epilogue.

I've committed the following after a x86_64-linux bootstrap.


Bernd
PR bootstrap/50621
	* config/i386/i386.c (ix86_add_cfa_restore_note): Omit notes only
	if the function was not shrink-wrapped.
	(ix86_expand_epilogue): Ensure queued cfa_adjust notes are attached
	to an insn.
	* function.c (thread_prologue_and_epilogue_insns): Make sure the
	shrink_wrapped flag is set even if there is no dump file.

Comments

Ian Lance Taylor Oct. 5, 2011, 11:04 p.m. UTC | #1
On Wed, Oct 5, 2011 at 10:17 AM, Bernd Schmidt <bernds@codesourcery.com> wrote:
>
> I've committed the following after a x86_64-linux bootstrap.

This patch appears to have broken the Go bootstrap when compiling a C
file in libgo.  Here is a reduced test case:

static struct
{
  int n;
  unsigned int m;
  _Bool f;
} g;

_Bool
f (int s)
{
  unsigned int b, m;

  if (!g.f)
    return 0;
  b = 1 << s;
  while (1)
    {
      m = g.m;
      if (m & b)
        break;
      if (__sync_bool_compare_and_swap (&g.m, m, m|b))
        {
          if (m == 0)
            f2 (&g.n);
          break;
        }
    }
  return 1;
}

Compiling this file with -O2 -fsplit-stack causes an ICE:

foo.c:29:1: internal compiler error: in maybe_record_trace_start, at
dwarf2cfi.c:2243

Compiling the file with -O2 -fsplit-stack -fno-shrink-wrap works.

Ian
diff mbox

Patch

Index: gcc/config/i386/i386.c
===================================================================
--- gcc/config/i386/i386.c	(revision 179553)
+++ gcc/config/i386/i386.c	(working copy)
@@ -9134,7 +9134,8 @@  static GTY(()) rtx queued_cfa_restores;
 static void
 ix86_add_cfa_restore_note (rtx insn, rtx reg, HOST_WIDE_INT cfa_offset)
 {
-  if (cfa_offset <= cfun->machine->fs.red_zone_offset)
+  if (!crtl->shrink_wrapped
+      && cfa_offset <= cfun->machine->fs.red_zone_offset)
     return;
 
   if (insn)
@@ -10738,6 +10739,8 @@  ix86_expand_epilogue (int style)
 				 GEN_INT (m->fs.sp_offset - UNITS_PER_WORD),
 				 style, true);
     }
+  else
+    ix86_add_queued_cfa_restore_notes (get_last_insn ());
 
   /* Sibcall epilogues don't want a return instruction.  */
   if (style == 0)
Index: gcc/function.c
===================================================================
--- gcc/function.c	(revision 179553)
+++ gcc/function.c	(working copy)
@@ -5741,10 +5741,11 @@  thread_prologue_and_epilogue_insns (void
 	  if (dump_file)
 	    fprintf (dump_file, "Shrink-wrapping aborted due to clobber.\n");
 	}
-      else if (dump_file && entry_edge != orig_entry_edge)
+      else if (entry_edge != orig_entry_edge)
 	{
 	  crtl->shrink_wrapped = true;
-	  fprintf (dump_file, "Performing shrink-wrapping.\n");
+	  if (dump_file)
+	    fprintf (dump_file, "Performing shrink-wrapping.\n");
 	}
 
     fail_shrinkwrap: