From patchwork Tue Nov 16 22:59:30 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 71470 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 77751B70F4 for ; Wed, 17 Nov 2010 09:59:45 +1100 (EST) Received: (qmail 3525 invoked by alias); 16 Nov 2010 22:59:41 -0000 Received: (qmail 3509 invoked by uid 22791); 16 Nov 2010 22:59:40 -0000 X-SWARE-Spam-Status: No, hits=-6.3 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; Tue, 16 Nov 2010 22:59:34 +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.13.8/8.13.8) with ESMTP id oAGMxXqi021534 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 16 Nov 2010 17:59:33 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id oAGMxVpN001339 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 16 Nov 2010 17:59:33 -0500 Received: from tyan-ft48-01.lab.bos.redhat.com (localhost.localdomain [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id oAGMxURj009767 for ; Tue, 16 Nov 2010 23:59:30 +0100 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id oAGMxUNM009765 for gcc-patches@gcc.gnu.org; Tue, 16 Nov 2010 23:59:30 +0100 Date: Tue, 16 Nov 2010 23:59:30 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Teach alias oracle about threading barriers (PR middle-end/45838) Message-ID: <20101116225930.GP29412@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes 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 Hi! pr34513.{c,C} testcases now fail on pa since the additions of leaf attributes. We have: #pragma omp parallel num_threads (thrs) { static int shrd = 0; #pragma omp atomic shrd += 1; #pragma omp barrier if (shrd != thrs) #pragma omp atomic errors += 1; } and as pa doesn't have corresponding __sync_ builtin, GOMP_atomic_{start,end} is used around the shrd increment. As most of the GOMP_* builtins (those that can't call functions in current TU) are now marked as leaf, GCC assumes shrd can't be modified by any of the calls, because it is a local static without address taken. But multiple threads can (and in this case do) modify the variable, so we can't cache its value across the barriers. __sync_* builtins are documented as barriers (most of them full memory barriers) and several GOMP_* functions are also barrier points. Fixed by teaching the alias oracle that threading barriers conflict with any refs that may_be_aliased, bootstrapped/regtested on x86_64-linux and i686-linux and tested on the testcase with a cross to hppa. Ok for trunk? 2010-11-16 Jakub Jelinek Richard Guenther PR middle-end/45838 * tree-ssa-alias.c (ref_maybe_used_by_call_p_1, call_may_clobber_ref_p_1): Return true for __sync_* and some OpenMP builtins that act as threading barriers. Jakub --- gcc/tree-ssa-alias.c.jj 2010-11-01 09:07:22.000000000 +0100 +++ gcc/tree-ssa-alias.c 2010-11-16 14:33:21.000000000 +0100 @@ -1209,6 +1209,28 @@ ref_maybe_used_by_call_p_1 (gimple call, case BUILT_IN_SINCOSF: case BUILT_IN_SINCOSL: return false; + /* __sync_* builtins and some OpenMP builtins act as threading + barriers. */ +#undef DEF_SYNC_BUILTIN +#define DEF_SYNC_BUILTIN(ENUM, NAME, TYPE, ATTRS) case ENUM: +#include "sync-builtins.def" +#undef DEF_SYNC_BUILTIN + case BUILT_IN_GOMP_ATOMIC_START: + case BUILT_IN_GOMP_ATOMIC_END: + case BUILT_IN_GOMP_BARRIER: + case BUILT_IN_GOMP_TASKWAIT: + case BUILT_IN_GOMP_CRITICAL_START: + case BUILT_IN_GOMP_CRITICAL_END: + case BUILT_IN_GOMP_CRITICAL_NAME_START: + case BUILT_IN_GOMP_CRITICAL_NAME_END: + case BUILT_IN_GOMP_LOOP_END: + case BUILT_IN_GOMP_ORDERED_START: + case BUILT_IN_GOMP_ORDERED_END: + case BUILT_IN_GOMP_PARALLEL_END: + case BUILT_IN_GOMP_SECTIONS_END: + case BUILT_IN_GOMP_SINGLE_COPY_START: + case BUILT_IN_GOMP_SINGLE_COPY_END: + return true; default: /* Fallthru to general call handling. */; @@ -1465,6 +1487,28 @@ call_may_clobber_ref_p_1 (gimple call, a return (ptr_deref_may_alias_ref_p_1 (sin, ref) || ptr_deref_may_alias_ref_p_1 (cos, ref)); } + /* __sync_* builtins and some OpenMP builtins act as threading + barriers. */ +#undef DEF_SYNC_BUILTIN +#define DEF_SYNC_BUILTIN(ENUM, NAME, TYPE, ATTRS) case ENUM: +#include "sync-builtins.def" +#undef DEF_SYNC_BUILTIN + case BUILT_IN_GOMP_ATOMIC_START: + case BUILT_IN_GOMP_ATOMIC_END: + case BUILT_IN_GOMP_BARRIER: + case BUILT_IN_GOMP_TASKWAIT: + case BUILT_IN_GOMP_CRITICAL_START: + case BUILT_IN_GOMP_CRITICAL_END: + case BUILT_IN_GOMP_CRITICAL_NAME_START: + case BUILT_IN_GOMP_CRITICAL_NAME_END: + case BUILT_IN_GOMP_LOOP_END: + case BUILT_IN_GOMP_ORDERED_START: + case BUILT_IN_GOMP_ORDERED_END: + case BUILT_IN_GOMP_PARALLEL_END: + case BUILT_IN_GOMP_SECTIONS_END: + case BUILT_IN_GOMP_SINGLE_COPY_START: + case BUILT_IN_GOMP_SINGLE_COPY_END: + return true; default: /* Fallthru to general call handling. */; }