Jeff Law wrote: On 07/26/2017 05:29 PM, Wilco Dijkstra wrote: > > But then the check size_align % MAX_SUPPORTED_STACK_ALIGNMENT != 0 > > seems wrong too given that round_push uses a different alignment to align > > to. > I had started to dig into the history of this code, but just didn't have > the time to do so fully before needing to leave for the day. To some > degree I was hoping you knew the rationale behind the test against > MAX_SUPPORTED_STACK_ALIGNMENT and I wouldn't have to do a ton of digging :-)
I looked further into this - it appears this works correctly since it is only bypassed if size_align is already maximally aligned. round_push aligns to the preferred alignment, which may be lower or equal to MAX_SUPPORTED_STACK_ALIGNMENT (which is at least STACK_BOUNDARY). Here is the updated version: ChangeLog: 2017-08-22 Wilco Dijkstra <wdijk...@arm.com> * explow.c (get_dynamic_stack_size): Improve dynamic alignment. diff --git a/gcc/explow.c b/gcc/explow.c index 50074e281edd5270c76d29feac6b7a92f598d11d..d3148273030a010ece1f8ea1c14eef64bbf4e78a 100644 --- a/gcc/explow.c +++ b/gcc/explow.c @@ -1234,15 +1234,20 @@ get_dynamic_stack_size (rtx *psize, unsigned size_align, example), so we must preventively align the value. We leave space in SIZE for the hole that might result from the alignment operation. */ - extra = (required_align - BITS_PER_UNIT) / BITS_PER_UNIT; - size = plus_constant (Pmode, size, extra); - size = force_operand (size, NULL_RTX); - - if (flag_stack_usage_info && pstack_usage_size) - *pstack_usage_size += extra; + /* Since the stack is presumed to be aligned before this allocation, + we only need to increase the size of the allocation if the required + alignment is more than the stack alignment. */ + if (required_align > STACK_BOUNDARY) + { + extra = (required_align - STACK_BOUNDARY) / BITS_PER_UNIT; + size = plus_constant (Pmode, size, extra); + size = force_operand (size, NULL_RTX); + if (size_align > STACK_BOUNDARY) + size_align = STACK_BOUNDARY; - if (extra && size_align > BITS_PER_UNIT) - size_align = BITS_PER_UNIT; + if (flag_stack_usage_info && pstack_usage_size) + *pstack_usage_size += extra; + } /* Round the size to a multiple of the required stack alignment. Since the stack is presumed to be rounded before this allocation,