From patchwork Tue Sep 11 12:21:01 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 183086 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 5E1B02C0089 for ; Tue, 11 Sep 2012 22:21:29 +1000 (EST) Comment: DKIM? See http://www.dkim.org DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=gcc.gnu.org; s=default; x=1347970890; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject: References:In-Reply-To:Content-Type:Mailing-List:Precedence: List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender: Delivered-To; bh=kQtrlpzcunPmBnUvS6D9x8LpFbg=; b=M3t786vqYE9YKlc t9zLJVCpVDThQrpTQLK7smghioWJ6s5MSLUw9G3Zg+XSOgcOMZE4J2o7fde+WAB6 8bDougBMX6yiWj5b44QO4TntxA2KBruEGDmUPD1+jR3+0WOAXSxxxjVAkbK5SHwE e4CPxO4JTDx3dhvcRYeDN7EAM1yI= Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=default; d=gcc.gnu.org; h=Received:Received:X-SWARE-Spam-Status:X-Spam-Check-By:Received:Received:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=G3y++DuZseaf42RcIGB6HcjEk7woUIRSx5ru1+qYWXOEqCsCn+dIYObCSzsXzW KawZAM9uTdtiboY7M6BjxysxTIBF9yIFjYAIoKUEE4AwDk9qm6bjqGkgnz7+wNJe AerYC/V4T7qmeToTemMFU04DtzZr4/U20HBHrJiH+yyIw=; Received: (qmail 28866 invoked by alias); 11 Sep 2012 12:21:22 -0000 Received: (qmail 28856 invoked by uid 22791); 11 Sep 2012 12:21:20 -0000 X-SWARE-Spam-Status: No, hits=-7.2 required=5.0 tests=AWL, BAYES_00, KHOP_RCVD_UNTRUST, KHOP_THREADED, RCVD_IN_DNSWL_HI, RCVD_IN_HOSTKARMA_W, RP_MATCHES_RCVD, SPF_HELO_PASS, TW_TM X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 11 Sep 2012 12:21:04 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q8BCL35p014501 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 11 Sep 2012 08:21:03 -0400 Received: from houston.quesejoda.com (vpn-8-21.rdu.redhat.com [10.11.8.21]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q8BCL255024414; Tue, 11 Sep 2012 08:21:02 -0400 Message-ID: <504F2CAD.3060005@redhat.com> Date: Tue, 11 Sep 2012 07:21:01 -0500 From: Aldy Hernandez User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120828 Thunderbird/15.0 MIME-Version: 1.0 To: Richard Guenther CC: gcc-patches , Andrew MacLeod Subject: Re: [patch] PR54149: fix data race in LIM pass References: <504E7476.9070103@redhat.com> In-Reply-To: Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org > ok with > > && gimple_assign_lhs_ptr (loc->stmt) == loc->ref > > instead. Let's hope we conservatively catch all writes to ref this way (which > is what we need, right)? Yes. Thanks. Committing the attached patch. PR middle-end/54149 * tree-ssa-loop-im.c (execute_sm_if_changed_flag_set): Only set flag for writes. diff --git a/gcc/testsuite/gcc.dg/simulate-thread/speculative-store-4.c b/gcc/testsuite/gcc.dg/simulate-thread/speculative-store-4.c new file mode 100644 index 0000000..59f81b7 --- /dev/null +++ b/gcc/testsuite/gcc.dg/simulate-thread/speculative-store-4.c @@ -0,0 +1,54 @@ +/* { dg-do link } */ +/* { dg-options "--param allow-store-data-races=0" } */ +/* { dg-final { simulate-thread } } */ + +#include +#include + +#include "simulate-thread.h" + +/* PR 54139 */ +/* Test that speculative stores do not happen for --param + allow-store-data-races=0. */ + +int g_13=1, insns=1; + +__attribute__((noinline)) +void simulate_thread_main() +{ + int l_245; + + /* Since g_13 is unilaterally set positive above, there should be + no store to g_13 below. */ + for (l_245 = 0; l_245 <= 1; l_245 += 1) + for (; g_13 <= 0; g_13 = 1) + ; +} + +int main() +{ + simulate_thread_main (); + simulate_thread_done (); + return 0; +} + +void simulate_thread_other_threads () +{ + ++g_13; + ++insns; +} + +int simulate_thread_step_verify () +{ + return 0; +} + +int simulate_thread_final_verify () +{ + if (g_13 != insns) + { + printf("FAIL: g_13 was incorrectly cached\n"); + return 1; + } + return 0; +} diff --git a/gcc/tree-ssa-loop-im.c b/gcc/tree-ssa-loop-im.c index 0f61631..67cab3a 100644 --- a/gcc/tree-ssa-loop-im.c +++ b/gcc/tree-ssa-loop-im.c @@ -2113,9 +2113,14 @@ execute_sm_if_changed_flag_set (struct loop *loop, mem_ref_p ref) gimple_stmt_iterator gsi; gimple stmt; - gsi = gsi_for_stmt (loc->stmt); - stmt = gimple_build_assign (flag, boolean_true_node); - gsi_insert_after (&gsi, stmt, GSI_CONTINUE_LINKING); + /* Only set the flag for writes. */ + if (is_gimple_assign (loc->stmt) + && gimple_assign_lhs_ptr (loc->stmt) == loc->ref) + { + gsi = gsi_for_stmt (loc->stmt); + stmt = gimple_build_assign (flag, boolean_true_node); + gsi_insert_after (&gsi, stmt, GSI_CONTINUE_LINKING); + } } VEC_free (mem_ref_loc_p, heap, locs); return flag;