On 11/14/13 04:52, Eric Botcazou wrote:
Hi,
we have a test in the gnat.dg testsuite (stack_usage1.adb) which checks that
the allocation of big temporaries created in non-overlapping blocks on the
stack is optimal, i.e. that they share a stack slot. It is run at -O0 and
passes. If you run it at -O2, it also passes. Now, if you run it at -O1, it
fails and that's a regression from the pre-TREE_CLOBBER_P era.
The problem is that, when optimization is enabled, DECL_IGNORED_P variables
are removed from blocks by remove_unused_scope_block_p and moved to the
toplevel. Now defer_stack_allocation has:
/* Variables in the outermost scope automatically conflict with
every other variable. The only reason to want to defer them
at all is that, after sorting, we can more efficiently pack
small variables in the stack frame. Continue to defer at -O2. */
if (toplevel && optimize < 2)
return false;
The comment is slightly obsolete in the TREE_CLOBBER_P era, since toplevel
variables don't necessarily conflict with each other, for example the above
variables moved to toplevel by remove_unused_scope_block_p.
We don't think that we need to tweak again remove_unused_scope_block_p in the
TREE_CLOBBER_P era; instead we can defer the allocation of big DECL_IGNORED_P
variables at toplevel from defer_stack_allocation.
Tested on x86_64-suse-linux, OK for the mainline?
2013-11-14 Olivier Hainque <hain...@adacore.com>
* cfgexpand.c (defer_stack_allocation): When optimization is enabled,
defer allocation of DECL_IGNORED_P variables at toplevel unless really
small. Factorize size threshold computation from the existing one.
(expand_used_vars): Refine comment.
2013-11-14 Eric Botcazou <ebotca...@adacore.com>
* gnat.dg/stack_usage1b.adb: New test.
* gnat.dg/stack_usage1c.adb: Likewise.
This looks fine to me.
Thanks,
jeff