diff mbox

Disable shrink-wrapping for ix86_static_chain_on_stack functions (PR target/67770)

Message ID 20151118231842.GP5675@tucnak.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek Nov. 18, 2015, 11:18 p.m. UTC
Hi!

As the testcase shows, shrink-wrapping is incompatible with
ix86_static_chain_on_stack, where we rely on the very first instruction
in the (nested) function to be pushl %esi and use alternate entry
point right after that pushl instruction (one byte after the start of
the nested function).  If shrink-wrapping moves the prologue somewhere else,
then this is no longer true.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk/5.3?

2015-11-18  Jakub Jelinek  <jakub@redhat.com>

	PR target/67770
	* config/i386/i386.md (simple_return): Disable if
	ix86_static_chain_on_stack is true.

	* gcc.target/i386/pr67770.c: New test.


	Jakub

Comments

Bernd Schmidt Nov. 19, 2015, 12:24 a.m. UTC | #1
On 11/19/2015 12:18 AM, Jakub Jelinek wrote:
> As the testcase shows, shrink-wrapping is incompatible with
> ix86_static_chain_on_stack, where we rely on the very first instruction
> in the (nested) function to be pushl %esi and use alternate entry
> point right after that pushl instruction (one byte after the start of
> the nested function).  If shrink-wrapping moves the prologue somewhere else,
> then this is no longer true.
>
> 	PR target/67770
> 	* config/i386/i386.md (simple_return): Disable if
> 	ix86_static_chain_on_stack is true.
>
> 	* gcc.target/i386/pr67770.c: New test.

Looks reasonable. Ok.


Bernd
diff mbox

Patch

--- gcc/config/i386/i386.md.jj	2015-11-14 19:36:03.000000000 +0100
+++ gcc/config/i386/i386.md	2015-11-18 17:49:51.648115096 +0100
@@ -12187,10 +12187,14 @@  (define_expand "return"
 ;; We need to disable this for TARGET_SEH, as otherwise
 ;; shrink-wrapped prologue gets enabled too.  This might exceed
 ;; the maximum size of prologue in unwind information.
+;; Also disallow shrink-wrapping if using stack slot to pass the
+;; static chain pointer - the first instruction has to be pushl %esi
+;; and it can't be moved around, as we use alternate entry points
+;; in that case.
 
 (define_expand "simple_return"
   [(simple_return)]
-  "!TARGET_SEH"
+  "!TARGET_SEH && !ix86_static_chain_on_stack"
 {
   if (crtl->args.pops_args)
     {
--- gcc/testsuite/gcc.target/i386/pr67770.c.jj	2015-11-18 17:38:13.940956205 +0100
+++ gcc/testsuite/gcc.target/i386/pr67770.c	2015-11-18 17:53:22.354143509 +0100
@@ -0,0 +1,40 @@ 
+/* PR target/67770 */
+/* { dg-do run { target ia32 } } */
+/* { dg-require-effective-target trampolines } */
+/* { dg-options "-O2" } */
+
+#ifndef NO_TRAMPOLINES
+__attribute__ ((noinline)) void
+foo (int i, void (* __attribute__ ((regparm (3))) bar) (int))
+{
+  bar (i);
+}
+#endif
+
+int
+main ()
+{
+#ifndef NO_TRAMPOLINES
+  int p = 0;
+
+  __attribute__ ((regparm (3), noinline)) void
+  bar (int i)
+  {
+    if (__builtin_expect (i, 0))
+      ++p;
+  }
+
+  foo (0, bar);
+  bar (0);
+
+  if (p != 0)
+    __builtin_abort ();
+
+  foo (1, bar);
+  bar (1);
+
+  if (p != 2)
+    __builtin_abort ();
+#endif
+  return 0;
+}