This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: -fno-tree-cselim not working?


David Miller <davem@davemloft.net> writes:

> Even in cases like:
> 
> typedef unsigned char spinlock_t;
> extern int spin_trylock(spinlock_t *);
> extern int spin_unlock(spinlock_t *);
> 
> struct foo {
>        spinlock_t lock;
>        int a;
> };
> 
> extern void foo_register(struct foo *p);
> extern void foo_unregister(struct foo *p);
> 
> void example(void)
> {
> 	struct foo local;
> 
> 	foo_register(&local);
> 
> 	if (spin_trylock(&local.lock)) {
> 		local.a++;
> 		spin_unlock(&local.lock);
> 	}
> 
> 	foo_unregister(&local);
> }
> 
> 
> I suspect that local.a++ will be represented as a frame relative
> access.  Test compiles show that gcc does update the on-stack
> copy on Sparc, now just to check if the conditional memory
> operation cases trigger here too.

This code isn't going to be a problem, because spin_unlock presumably
includes a memory barrier.

The cases which are problems are the ones in which there is no memory
barrier, as in the original example.

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]