From patchwork Fri Mar 23 15:46:44 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aldy Hernandez X-Patchwork-Id: 148456 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 07458B6EE8 for ; Sat, 24 Mar 2012 02:47:08 +1100 (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=1333122429; h=Comment: DomainKey-Signature:Received:Received:Received:Received:Received: Message-ID:Date:From:User-Agent:MIME-Version:To:Subject: Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:Sender:Delivered-To; bh=yMKGujq 0LNVRsSMK7spyTuQfqys=; b=t9ktBNK9C0TYfyBF9+h1xhP3v7ECMoD2ALKdaVW 5Zmi5eHwoaKmK7QovjL4ox8r+Rtim7uCgWAHaAAbADCsa7R0eTrBVXopP0XfkvC8 izO8nSyt6ShVXm5Wzg5XEbWQVXpiW/xE4Swn6j4Ou26l7jngNmhySZUyWRrMpRoG 6j0g= 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:Subject:Content-Type:Mailing-List:Precedence:List-Id:List-Unsubscribe:List-Archive:List-Post:List-Help:Sender:Delivered-To; b=LdER8mHu5h05uSUz12itnfEoix5uWp6NKM4uG36NfUoEFLi+jCrxhUQWzfDuFC dKIJxEWVNKJO0xRjZcfxgq4m3oQj1H0/xLq+Zj2FYYiCrg4jFBgPX5N6x3fR55lk qxcmjn7IeLTqigYbup4ytidVT38qM2HaugLh0p0BY8lQA=; Received: (qmail 8187 invoked by alias); 23 Mar 2012 15:47:00 -0000 Received: (qmail 8065 invoked by uid 22791); 23 Mar 2012 15:46:58 -0000 X-SWARE-Spam-Status: No, hits=-6.7 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD 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; Fri, 23 Mar 2012 15:46:45 +0000 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q2NFkj6Y025294 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 23 Mar 2012 11:46:45 -0400 Received: from houston.quesejoda.com (vpn-224-154.phx2.redhat.com [10.3.224.154]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q2NFkiqZ023051; Fri, 23 Mar 2012 11:46:44 -0400 Message-ID: <4F6C9AE4.3070103@redhat.com> Date: Fri, 23 Mar 2012 10:46:44 -0500 From: Aldy Hernandez User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.1) Gecko/20120216 Thunderbird/10.0.1 MIME-Version: 1.0 To: Andrew MacLeod , Torvald Riegel , gcc-patches Subject: [C11-atomic] new test: limit precomputing values across acquire barriers 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 This is a similar test to the previous acquire test. Here we are incorrectly caching 'x' and failing to reload it after the __ATOMIC_ACQUIRE. + i = x + y; + + if (__atomic_load_n (&flag, __ATOMIC_ACQUIRE)) + { + /* x here should not be reused from above. */ + k = x; + } Note that there is technically a data race on the load of x+y. See the explanation on my previous testcase. OK for branch? Index: testsuite/gcc.dg/simulate-thread/atomic-hoist-2.c =================================================================== --- testsuite/gcc.dg/simulate-thread/atomic-hoist-2.c (revision 0) +++ testsuite/gcc.dg/simulate-thread/atomic-hoist-2.c (revision 0) @@ -0,0 +1,60 @@ +/* { dg-do link } */ +/* { dg-require-effective-target sync_int_long } */ +/* { dg-final { simulate-thread } } */ + +/* Test that a load is not precomputed before an acquire. */ + +#include +#include "simulate-thread.h" + +int flag=0; +int x = 0, y = 10, i = 0, k = -1; + +__attribute__((noinline)) +void simulate_thread_main() +{ + /* Test that the first load of x is not cached and reused in the second + load of x. */ + + /* Note: Technically this first load of x/y is a data race. See + note on atomic-hoist-1.c. */ + i = x + y; + + if (__atomic_load_n (&flag, __ATOMIC_ACQUIRE)) + { + /* x here should not be reused from above. */ + k = x; + } +} + +void simulate_thread_other_threads () +{ + /* Once i has been calculated in thread 1, change the value of x. */ + if (i != 0) + { + x = -1; + flag = 1; + } +} + +int simulate_thread_step_verify () +{ + return 0; +} + +int simulate_thread_final_verify () +{ + if (k != -1) + { + printf("FAIL: k != -1\n"); + return 1; + } + return 0; +} + +main() +{ + simulate_thread_main (); + simulate_thread_done (); + return 0; +}