From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 659 invoked by alias); 29 Oct 2007 16:32:42 -0000 Received: (qmail 646 invoked by uid 22791); 29 Oct 2007 16:32:40 -0000 X-Spam-Check-By: sourceware.org Received: from us02smtp1.synopsys.com (HELO vaxjo.synopsys.com) (198.182.60.75) by sourceware.org (qpsmtpd/0.31) with ESMTP; Mon, 29 Oct 2007 16:32:33 +0000 Received: from crone.synopsys.com (crone.synopsys.com [146.225.7.23]) by vaxjo.synopsys.com (Postfix) with ESMTP id A0234DDDD; Mon, 29 Oct 2007 09:32:31 -0700 (PDT) Received: from piper.synopsys.com (localhost [127.0.0.1]) by crone.synopsys.com (8.9.1/8.9.1) with ESMTP id JAA00657; Mon, 29 Oct 2007 09:30:50 -0700 (PDT) Received: from piper.synopsys.com (localhost [127.0.0.1]) by piper.synopsys.com (8.12.11/8.12.3) with ESMTP id l9TGWUZB010758; Mon, 29 Oct 2007 09:32:30 -0700 Received: (from jbuck@localhost) by piper.synopsys.com (8.12.11/8.12.11/Submit) id l9TGWUW5010756; Mon, 29 Oct 2007 09:32:30 -0700 Date: Mon, 29 Oct 2007 16:47:00 -0000 From: Joe Buck To: David Miller Cc: darryl-mailinglists@netbauds.net, dave.korn@artimi.com, tomash.brechko@gmail.com, matz@suse.de, gcc@gcc.gnu.org Subject: Re: Optimization of conditional access to globals: thread-unsafe? Message-ID: <20071029163230.GB10611@synopsys.com> References: <02e801c819c9$48396120$2e08a8c0@CAM.ARTIMI.COM> <20071028.183730.37179404.davem@davemloft.net> <4725675D.6000404@netbauds.net> <20071028.221738.18826511.davem@davemloft.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20071028.221738.18826511.davem@davemloft.net> User-Agent: Mutt/1.4.1i Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2007-10/txt/msg00711.txt.bz2 On Sun, Oct 28, 2007 at 10:17:38PM -0700, David Miller wrote: > From: Darryl Miles > 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.