This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Optimization of conditional access to globals: thread-unsafe?
On Sun, Oct 28, 2007 at 10:17:38PM -0700, David Miller wrote:
> From: Darryl Miles <darryl-mailinglists@netbauds.net>
> Date: Mon, 29 Oct 2007 04:53:49 +0000
>
> > What are the issues with "speculative loads" ?
>
> The conditional might be protecting whether the pointer is valid and
> can be dereferenced at all.
>
> int *counter;
>
> void foo(int counter_is_valid)
> {
> if (counter_is_valid)
> (*counter)++;
> }
GCC will never do a speculative access in this case. That's because
"counter_is_valid" might really mean "counter_is_non_null".
It seems that the original issue can only occur if there is a direct
write to a global, not a write through a pointer.