Thread (305 messages) 305 messages, 27 authors, 2007-09-11

Re: [PATCH 0/24] make atomic_read() behave consistently across all architectures

From: Segher Boessenkool <hidden>
Date: 2007-08-17 22:30:52
Also in: lkml, netdev

In a reasonable world, gcc should just make that be (on x86)

	addl $1,i(%rip)

on x86-64, which is indeed what it does without the volatile. But with 
the
volatile, the compiler gets really nervous, and doesn't dare do it in 
one
instruction, and thus generates crap like

        movl    i(%rip), %eax
        addl    $1, %eax
        movl    %eax, i(%rip)

instead. For no good reason, except that "volatile" just doesn't have 
any
good/clear semantics for the compiler, so most compilers will just 
make it
be "I will not touch this access in any way, shape, or form". Including
even trivially correct instruction optimization/combination.
It's just a (target-specific, perhaps) missed-optimisation kind
of bug in GCC.  Care to file a bug report?
but is
(again) something that gcc doesn't dare do, since "i" is volatile.
Just nobody taught it it can do this; perhaps no one wanted to
add optimisations like that, maybe with a reasoning like "people
who hit the go-slow-in-unspecified-ways button should get what
they deserve" ;-)


Segher
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help