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

Reply via email to