http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54087

--- Comment #3 from Ulrich Drepper <drepper.fsp at gmail dot com> 2012-08-01 
16:06:33 UTC ---
(In reply to comment #2)
> (In reply to comment #1)
> > Use __atomic_add_fetch and __atomic_fetch_sub in the testcase, and you will
> 
> Eh, __atomic_fetch_add.

Yes, but the compiler should automatically do this.  The extreme case is this:


int v;

int a(void)
{
  return __sync_sub_and_fetch(&v, 5);
}

int b(void)
{
  return __sync_add_and_fetch(&v, -5);
}


The second function does compile as expected.  The first doesn't, it uses
cmpxchg.

Shouldn't this be easy enough to fix by adding patterns for atomic_fetch_sub
and atomic_sub_fetch which match if the second parameter is a constant?  If
it's not a constant a bit more code is needed but that should be no problem
either.

Reply via email to