On Fri, Aug 3, 2018 at 12:55 AM, H.J. Lu <[email protected]> wrote:
> We should always set cfun->machine->max_used_stack_alignment if the
> maximum stack slot alignment may be greater than 64 bits.
>
> Tested on i686 and x86-64. OK for master and backport for GCC 8?
Can you explain why 64 bits, and what this value represents? Is this
value the same for 64bit and 32bit targets?
Should crtl->max_used_stack_slot_alignment be compared to
STACK_BOUNDARY or even MIN_STACK_BOUNDARY instead?
Uros.
> Thanks.
>
> H.J.
> ----
> gcc/
>
> PR target/86386
> * config/i386/i386.c (ix86_finalize_stack_frame_flags): Set
> cfun->machine->max_used_stack_alignment if needed.
>
> gcc/testsuite/
>
> PR target/86386
> * gcc.target/i386/pr86386.c: New file.
> ---
> gcc/config/i386/i386.c | 6 +++---
> gcc/testsuite/gcc.target/i386/pr86386.c | 26 +++++++++++++++++++++++++
> 2 files changed, 29 insertions(+), 3 deletions(-)
> create mode 100644 gcc/testsuite/gcc.target/i386/pr86386.c
>
> diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
> index ee409cfe7e4..4a0a050b3a2 100644
> --- a/gcc/config/i386/i386.c
> +++ b/gcc/config/i386/i386.c
> @@ -13281,12 +13281,12 @@ ix86_finalize_stack_frame_flags (void)
> recompute_frame_layout_p = true;
> }
> }
> - else if (crtl->max_used_stack_slot_alignment
> - > crtl->preferred_stack_boundary)
> + else if (crtl->max_used_stack_slot_alignment > 64)
> {
> /* We don't need to realign stack. But we still need to keep
> stack frame properly aligned to satisfy the largest alignment
> - of stack slots. */
> + of stack slots if the maximum stack slot alignment may be
> + greater than 64 bits. */
> if (ix86_find_max_used_stack_alignment (stack_alignment, true))
> cfun->machine->max_used_stack_alignment
> = stack_alignment / BITS_PER_UNIT;
> diff --git a/gcc/testsuite/gcc.target/i386/pr86386.c
> b/gcc/testsuite/gcc.target/i386/pr86386.c
> new file mode 100644
> index 00000000000..a67cf45444e
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr86386.c
> @@ -0,0 +1,26 @@
> +/* PR target/86386 */
> +/* { dg-do run { target { avx_runtime && int128 } } } */
> +/* { dg-options "-Os -fno-tree-dce -mstringop-strategy=vector_loop -mavx" }
> */
> +
> +unsigned c, d, e, f;
> +
> +unsigned __attribute__((noipa))
> +foo (unsigned char g, unsigned short h, unsigned i, unsigned long long j,
> + unsigned char k, unsigned short l, unsigned m, unsigned __int128 n)
> +{
> + __builtin_memset (&e, 0, 3);
> + n <<= m;
> + __builtin_memcpy (&m, 2 + (char *) &n, 1);
> + m >>= 0;
> + d ^= __builtin_mul_overflow (l, n, &m);
> + return m;
> +}
> +
> +int
> +main ()
> +{
> + unsigned __int128 x = foo (0, 0, 0, 0, 0, 4, 1, 3);
> + if (x != 24)
> + __builtin_abort ();
> + return 0;
> +}
> --
> 2.17.1
>