Patchwork Fix shrink-wrapping with vDRAP (PR target/55940)

login
register
mail settings
Submitter Jakub Jelinek
Date Jan. 15, 2013, 10:38 p.m.
Message ID <20130115223831.GD7269@tucnak.redhat.com>
Download mbox | patch
Permalink /patch/212349/
State New
Headers show

Comments

Jakub Jelinek - Jan. 15, 2013, 10:38 p.m.
Hi!

As the following testcase shows, even when stack_realign_drap we might need
to prevent crtl->drap_reg accesses in the bbs considered for
shrink-wrapping, even if reload decides stack realignment isn't needed, the
vDRAP (in the testcase %edi) can be used by the first bbs and initialized
only later on in the prologue.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2013-01-15  Jakub Jelinek  <jakub@redhat.com>

	PR target/55940
	* function.c (thread_prologue_and_epilogue_insns): Always
	add crtl->drap_reg to set_up_by_prologue.set, even if
	stack_realign_drap is false.

	* gcc.dg/pr55940.c: New test.


	Jakub
Richard Henderson - Jan. 15, 2013, 10:53 p.m.
On 01/15/2013 02:38 PM, Jakub Jelinek wrote:
> 2013-01-15  Jakub Jelinek<jakub@redhat.com>
>
> 	PR target/55940
> 	* function.c (thread_prologue_and_epilogue_insns): Always
> 	add crtl->drap_reg to set_up_by_prologue.set, even if
> 	stack_realign_drap is false.
>
> 	* gcc.dg/pr55940.c: New test.

Ok.


r~
H.J. Lu - Jan. 16, 2013, 4:28 p.m.
On Tue, Jan 15, 2013 at 2:38 PM, Jakub Jelinek <jakub@redhat.com> wrote:
> Hi!
>
> As the following testcase shows, even when stack_realign_drap we might need
> to prevent crtl->drap_reg accesses in the bbs considered for
> shrink-wrapping, even if reload decides stack realignment isn't needed, the
> vDRAP (in the testcase %edi) can be used by the first bbs and initialized
> only later on in the prologue.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2013-01-15  Jakub Jelinek  <jakub@redhat.com>
>
>         PR target/55940
>         * function.c (thread_prologue_and_epilogue_insns): Always
>         add crtl->drap_reg to set_up_by_prologue.set, even if
>         stack_realign_drap is false.
>
>         * gcc.dg/pr55940.c: New test.
>
> --- gcc/function.c.jj   2013-01-11 09:02:55.000000000 +0100
> +++ gcc/function.c      2013-01-15 19:23:20.648826011 +0100
> @@ -6029,7 +6029,7 @@ thread_prologue_and_epilogue_insns (void
>        if (pic_offset_table_rtx)
>         add_to_hard_reg_set (&set_up_by_prologue.set, Pmode,
>                              PIC_OFFSET_TABLE_REGNUM);
> -      if (stack_realign_drap && crtl->drap_reg)
> +      if (crtl->drap_reg)
>         add_to_hard_reg_set (&set_up_by_prologue.set,
>                              GET_MODE (crtl->drap_reg),
>                              REGNO (crtl->drap_reg));

Does this cause

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56006
Jakub Jelinek - Jan. 16, 2013, 4:32 p.m.
On Wed, Jan 16, 2013 at 08:28:54AM -0800, H.J. Lu wrote:
> > --- gcc/function.c.jj   2013-01-11 09:02:55.000000000 +0100
> > +++ gcc/function.c      2013-01-15 19:23:20.648826011 +0100
> > @@ -6029,7 +6029,7 @@ thread_prologue_and_epilogue_insns (void
> >        if (pic_offset_table_rtx)
> >         add_to_hard_reg_set (&set_up_by_prologue.set, Pmode,
> >                              PIC_OFFSET_TABLE_REGNUM);
> > -      if (stack_realign_drap && crtl->drap_reg)
> > +      if (crtl->drap_reg)
> >         add_to_hard_reg_set (&set_up_by_prologue.set,
> >                              GET_MODE (crtl->drap_reg),
> >                              REGNO (crtl->drap_reg));
> 
> Does this cause
> 
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56006

No, it is caused by http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=195227
See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55547#c11

	Jakub

Patch

--- gcc/function.c.jj	2013-01-11 09:02:55.000000000 +0100
+++ gcc/function.c	2013-01-15 19:23:20.648826011 +0100
@@ -6029,7 +6029,7 @@  thread_prologue_and_epilogue_insns (void
       if (pic_offset_table_rtx)
 	add_to_hard_reg_set (&set_up_by_prologue.set, Pmode,
 			     PIC_OFFSET_TABLE_REGNUM);
-      if (stack_realign_drap && crtl->drap_reg)
+      if (crtl->drap_reg)
 	add_to_hard_reg_set (&set_up_by_prologue.set,
 			     GET_MODE (crtl->drap_reg),
 			     REGNO (crtl->drap_reg));
--- gcc/testsuite/gcc.dg/pr55940.c.jj	2013-01-15 20:33:21.288921765 +0100
+++ gcc/testsuite/gcc.dg/pr55940.c	2013-01-15 20:33:03.000000000 +0100
@@ -0,0 +1,54 @@ 
+/* PR target/55940 */
+/* { dg-do run } */
+/* { dg-options "-Os" } */
+/* { dg-additional-options "-mpreferred-stack-boundary=2" { target { { i?86-*-* x86_64-*-* } && ia32 } } } */
+
+struct S { int s; unsigned long t; };
+
+__attribute__ ((noinline, noclone)) unsigned long long
+bar (struct S *x, unsigned long y)
+{
+  asm volatile ("" : : "r" (x), "r" (y) : "memory");
+  return x->s + y;
+}
+
+__attribute__ ((noinline, noclone)) unsigned long long
+foo (struct S *x, unsigned long y)
+{
+  unsigned long a;
+  if (__builtin_expect (((__UINTPTR_TYPE__) (x) + 0x1000U < 0x2000U), 0))
+    return ~0ULL;
+  if (__builtin_expect (x->s <= 0 || x->s > 9, 0))
+    return ~0ULL;
+  a = x->t >> 12;
+  if (y == a)
+    return ~0ULL;
+  if (x->s == 3)
+    return x->t + y * 4096;
+  return bar (x, y);
+}
+
+int va, vb, vc, vd;
+
+int
+main ()
+{
+  struct S s;
+  asm volatile ("" : : : "memory");
+  int a = va, b = vb, c = vc, d = vd;
+  asm volatile ("" : : : "memory");
+  int i;
+  for (i = 0; i < 64; i++)
+    if (foo ((struct S *) 0, 0) != ~0ULL)
+      __builtin_abort ();
+  s.s = 3;
+  s.t = 2 << 12;
+  if (foo (&s, 2) != ~0ULL)
+    __builtin_abort ();
+  if (foo (&s, 3) != (2 << 12) + 3 * 4096)
+    __builtin_abort ();
+  asm volatile ("" : : : "memory");
+  va = a; vb = b; vc = c; vd = d;
+  asm volatile ("" : : : "memory");
+  return 0;
+}