From: Jakub Jelinek <jakub@redhat.com>
To: Richard Henderson <rth@redhat.com>,
Bernd Schmidt <bernds@codesourcery.com>
Cc: gcc-patches@gcc.gnu.org, "H.J. Lu" <hjl.tools@gmail.com>
Subject: [PATCH] Fix shrink-wrapping with vDRAP (PR target/55940)
Date: Tue, 15 Jan 2013 22:39:00 -0000 [thread overview]
Message-ID: <20130115223831.GD7269@tucnak.redhat.com> (raw)
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));
--- 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;
+}
Jakub
next reply other threads:[~2013-01-15 22:39 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-15 22:39 Jakub Jelinek [this message]
2013-01-15 22:53 ` Richard Henderson
2013-01-16 16:29 ` H.J. Lu
2013-01-16 16:32 ` Jakub Jelinek
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=20130115223831.GD7269@tucnak.redhat.com \
--to=jakub@redhat.com \
--cc=bernds@codesourcery.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=hjl.tools@gmail.com \
--cc=rth@redhat.com \
/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).