The following patch fixes http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57018
The patch was successfully bootstrapped and tested on x86/x86-64 (with different options).
Committed as rev. 198140. 2013-04-22 Vladimir Makarov <vmaka...@redhat.com> PR target/57018 * lra-eliminations.c (mark_not_eliminable): Prevent elimination of a set sp if no stack realignment. 2013-04-22 Vladimir Makarov <vmaka...@redhat.com> PR target/57018 * gcc.target/i386/pr57018.c: New test.
Index: lra-eliminations.c =================================================================== --- lra-eliminations.c (revision 198092) +++ lra-eliminations.c (working copy) @@ -716,7 +716,9 @@ mark_not_eliminable (rtx x) ep++) if (ep->to_rtx == SET_DEST (x) && SET_DEST (x) != hard_frame_pointer_rtx - && (GET_CODE (SET_SRC (x)) != PLUS + && (! (SUPPORTS_STACK_ALIGNMENT && stack_realign_fp + && REGNO (ep->to_rtx) == STACK_POINTER_REGNUM) + || GET_CODE (SET_SRC (x)) != PLUS || XEXP (SET_SRC (x), 0) != SET_DEST (x) || ! CONST_INT_P (XEXP (SET_SRC (x), 1)))) setup_can_eliminate (ep, false); Index: testsuite/gcc.target/i386/pr57018.c =================================================================== --- testsuite/gcc.target/i386/pr57018.c (revision 0) +++ testsuite/gcc.target/i386/pr57018.c (working copy) @@ -0,0 +1,31 @@ +/* { dg-do run } */ +/* { dg-options "-Os -fomit-frame-pointer -fno-asynchronous-unwind-tables" } */ +/* { dg-additional-options "-march=i686" { target ia32 } } */ + +struct A { char a[16]; } a; + +void __attribute__((noinline, noclone)) +foo (struct A b) +{ + if (__builtin_memcmp (b.a, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 16)) + __builtin_abort (); + asm volatile ("" : : : "memory"); +} + +void __attribute__((noinline, noclone)) +bar (struct A b) +{ + foo (a); + a = b; +} + +int +main () +{ + struct A b = { "\0\1\2\3\4\5\6\7\10\11\12\13\14\15\16\17" }; + bar (b); + if (__builtin_memcmp (a.a, b.a, 16)) + __builtin_abort (); + return 0; +} +