From 91539305a849cc8d8e8efb0d98e8c12541992916 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Sun, 5 Aug 2018 12:46:13 +0000 Subject: [PATCH] i386: Set cfun->machine->max_used_stack_alignment if needed cfun->machine->max_used_stack_alignment is used to decide how stack frame should be aligned. This is independent of any psABIs nor 32-bit vs 64-bit. It is always safe to compute max_used_stack_alignment. We compute it only if 128-bit aligned load/store may be generated on misaligned stack slot which will lead to segfault. 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. From-SVN: r263317 --- gcc/ChangeLog | 6 ++++++ gcc/config/i386/i386.c | 14 +++++++------ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.target/i386/pr86386.c | 26 +++++++++++++++++++++++++ 4 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr86386.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 7d2323983ec..720ce32a6ca 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2018-08-05 H.J. Lu + + PR target/86386 + * config/i386/i386.c (ix86_finalize_stack_frame_flags): Set + cfun->machine->max_used_stack_alignment if needed. + 2018-08-04 Martin Sebor PR tree-optimization/86571 diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index ee409cfe7e4..7554fd1f659 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -13281,12 +13281,14 @@ ix86_finalize_stack_frame_flags (void) recompute_frame_layout_p = true; } } - else if (crtl->max_used_stack_slot_alignment - > crtl->preferred_stack_boundary) - { - /* 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. */ + else if (crtl->max_used_stack_slot_alignment >= 128) + { + /* We don't need to realign stack. max_used_stack_alignment is + used to decide how stack frame should be aligned. This is + independent of any psABIs nor 32-bit vs 64-bit. It is always + safe to compute max_used_stack_alignment. We compute it only + if 128-bit aligned load/store may be generated on misaligned + stack slot which will lead to segfault. */ 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/ChangeLog b/gcc/testsuite/ChangeLog index a1f3b5bdcad..fb65bd04eff 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-08-05 H.J. Lu + + PR target/86386 + * gcc.target/i386/pr86386.c: New file. + 2018-08-04 Tom de Vries * lib/gcc-gdb-test.exp: Use absolute line number in pass/fail line. 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.30.2