This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/54087] __atomic_fetch_add does not use xadd instruction
- From: "drepper.fsp at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 01 Aug 2012 16:06:33 +0000
- Subject: [Bug target/54087] __atomic_fetch_add does not use xadd instruction
- Auto-submitted: auto-generated
- References: <bug-54087-4@http.gcc.gnu.org/bugzilla/>
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.