This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: -fno-tree-cselim not working?
- From: Ian Lance Taylor <iant at google dot com>
- To: Samuel Tardieu <sam at rfc1149 dot net>
- Cc: gcc at gcc dot gnu dot org
- Date: 25 Oct 2007 21:31:56 -0700
- Subject: Re: -fno-tree-cselim not working?
- References: <87myu7zf9a.fsf@willow.rfc1149.net>
Samuel Tardieu <sam@rfc1149.net> writes:
> #include <pthread.h>
>
> static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
> static int acquires_count = 0;
>
> int
> trylock()
> {
> int res;
>
> res = pthread_mutex_trylock(&mutex);
> if (res == 0)
> ++acquires_count;
>
> return res;
> }
>
> trylock:
> subl $12, %esp
> movl $mutex, (%esp)
> call pthread_mutex_trylock
> movl acquires_count, %edx
> cmpl $1, %eax
> adcl $0, %edx
> movl %edx, acquires_count
> addl $12, %esp
> ret
By the way, since this is getting play on LKML and no doubt other
places:
This optimization (or pessimization, depending) is not new. gcc 4.1
does the same thing. The code has been in there since at least gcc
3.4, though I didn't build gcc 3.4 to test what happened.
Code like needs to use volatile or explicit memory barriers.
Ian