https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86486
--- Comment #2 from Tamar Christina <tnfchris at gcc dot gnu.org> --- Author: tnfchris Date: Mon Oct 1 12:56:40 2018 New Revision: 264749 URL: https://gcc.gnu.org/viewcvs?rev=264749&root=gcc&view=rev Log: Add support for SVE stack clash probing. This patch adds basic support for SVE stack clash protection. It is a first implementation and will use a loop to do the probing and stack adjustments. An example sequence is: .cfi_startproc mov x15, sp cntb x16, all, mul #11 add x16, x16, 304 .cfi_def_cfa_register 15 .SVLPSPL0: cmp x16, 61440 b.lt .SVLPEND0 sub sp, sp, 61440 str xzr, [sp, 0] sub x16, x16, 61440 b .SVLPSPL0 .SVLPEND0: sub sp, sp, x16 .cfi_escape 0xf,0xc,0x8f,0,0x92,0x2e,0,0x8,0x58,0x1e,0x23,0xb0,0x2,0x22 for a 64KB guard size, and for a 4KB guard size .cfi_startproc mov x15, sp cntb x16, all, mul #11 add x16, x16, 304 .cfi_def_cfa_register 15 .SVLPSPL0: cmp x16, 3072 b.lt .SVLPEND0 sub sp, sp, 3072 str xzr, [sp, 0] sub x16, x16, 3072 b .SVLPSPL0 .SVLPEND0: sub sp, sp, x16 .cfi_escape 0xf,0xc,0x8f,0,0x92,0x2e,0,0x8,0x58,0x1e,0x23,0xb0,0x2,0x22 This has about the same semantics as alloca, except we prioritize the common case where no probe is required. We also change the amount we adjust the stack and the probing interval to be the nearest value to `guard size - abi buffer` that fits in the 12-bit shifted immediate used by cmp. While this would mean we probe a bit more often than we require, in practice the amount of SVE vectors you'd need to spill is significant. Even more so to enter the loop more than once. gcc/ PR target/86486 * config/aarch64/aarch64-protos.h (aarch64_output_probe_sve_stack_clash): New. * config/aarch64/aarch64.c (aarch64_output_probe_sve_stack_clash, aarch64_clamp_to_uimm12_shift): New. (aarch64_allocate_and_probe_stack_space): Add SVE specific section. * config/aarch64/aarch64.md (probe_sve_stack_clash): New. gcc/testsuite/ PR target/86486 * gcc.target/aarch64/stack-check-prologue-16.c: New test * gcc.target/aarch64/stack-check-cfa-3.c: New test. * gcc.target/aarch64/sve/struct_vect_24.c: New test. * gcc.target/aarch64/sve/struct_vect_24_run.c: New test. Added: trunk/gcc/testsuite/gcc.target/aarch64/stack-check-cfa-3.c trunk/gcc/testsuite/gcc.target/aarch64/stack-check-prologue-16.c trunk/gcc/testsuite/gcc.target/aarch64/sve/struct_vect_24.c trunk/gcc/testsuite/gcc.target/aarch64/sve/struct_vect_24_run.c Modified: trunk/gcc/ChangeLog trunk/gcc/config/aarch64/aarch64-protos.h trunk/gcc/config/aarch64/aarch64.c trunk/gcc/config/aarch64/aarch64.md trunk/gcc/testsuite/ChangeLog