This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Improve alloca alignment
- From: Wilco Dijkstra <Wilco dot Dijkstra at arm dot com>
- To: Jeff Law <law at redhat dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: nd <nd at arm dot com>
- Date: Tue, 22 Aug 2017 14:15:21 +0000
- Subject: Re: [PATCH] Improve alloca alignment
- Authentication-results: sourceware.org; auth=none
- Authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco dot Dijkstra at arm dot com;
- Nodisclaimer: True
- References: <DB6PR0801MB2053EFC180A8360BC943BEB883B90@DB6PR0801MB2053.eurprd08.prod.outlook.com> <9c8a4d59-92c6-9134-a415-d187dd153127@redhat.com> <DB6PR0801MB2053C589860FEBE267E5429483B90@DB6PR0801MB2053.eurprd08.prod.outlook.com>,<8dd9edf2-494b-66b4-09aa-5c4a984576c0@redhat.com>
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
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 <wdijkstr@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,