This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
New __atomic builtins generating an unwanted/unneeded stack slot
- From: Frederic Riss <frederic dot riss at gmail dot com>
- To: gcc <gcc at gcc dot gnu dot org>
- Date: Mon, 28 Oct 2013 10:25:21 +0100
- Subject: New __atomic builtins generating an unwanted/unneeded stack slot
- Authentication-results: sourceware.org; auth=none
I try to convert my port to the new memory-model-aware atomic
builtins, but I'm facing some code generation issue because of the
__atomic_compare_exchange prototype (passing the comparison value by
reference). For example, for a simple wrapper around
__atomic_compare_exchange, the code at the end of the middle-end looks
like this:
cas32 (int * addr, unsigned int old, unsigned int new)
{
_Bool D.1441;
int D.1439;
<bb 2>:
D.1441_3 = __atomic_compare_exchange_4 (addr_2(D), &old, new_7(D), 0, 2, 0);
D.1439_4 = (int) D.1441_3;
return D.1439_4;
}
The memory reference to 'old' forces the creation of a stack slot for
the value. Although the a CSE pass manages to remove the use of the
memory reference to the stack slot, the initialization of the stack
slot stays there and forces the creation of a frame for the function.
I suppose a dse pass could remove the store to the stack slot, but it
can't do a correct analyze, because the synchronization instructions
contain unspecs and barriers that are considered 'wild reads' by the
pass.
Is there a clean way to have the compiler discard the unneeded stack slot?
Thanks,
Fred