From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31442 invoked by alias); 9 Nov 2007 08:39:41 -0000 Received: (qmail 31426 invoked by uid 22791); 9 Nov 2007 08:39:40 -0000 X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (66.187.233.31) by sourceware.org (qpsmtpd/0.31) with ESMTP; Fri, 09 Nov 2007 08:39:38 +0000 Received: from int-mx1.corp.redhat.com (int-mx1.corp.redhat.com [172.16.52.254]) by mx1.redhat.com (8.13.8/8.13.1) with ESMTP id lA98daQ4019751; Fri, 9 Nov 2007 03:39:36 -0500 Received: from devserv.devel.redhat.com (devserv.devel.redhat.com [10.10.36.72]) by int-mx1.corp.redhat.com (8.13.1/8.13.1) with ESMTP id lA98dZfG008836; Fri, 9 Nov 2007 03:39:35 -0500 Received: from devserv.devel.redhat.com (localhost.localdomain [127.0.0.1]) by devserv.devel.redhat.com (8.12.11.20060308/8.12.11) with ESMTP id lA98dZBd003970; Fri, 9 Nov 2007 03:39:35 -0500 Received: (from jakub@localhost) by devserv.devel.redhat.com (8.12.11.20060308/8.12.11/Submit) id lA98dZpn003968; Fri, 9 Nov 2007 03:39:35 -0500 Date: Fri, 09 Nov 2007 11:49:00 -0000 From: Jakub Jelinek To: Richard Henderson , Diego Novillo Cc: gcc-patches@gcc.gnu.org Subject: [gomp] Fix !$omp atomic (PR fortran/34020) Message-ID: <20071109083935.GW5451@devserv.devel.redhat.com> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2007-11/txt/msg00511.txt.bz2 Hi! On the following testcase lhsaddr is (real4 *) lhs where lhs has real4 & type. But unshare_body unshares the NOP_EXPR, so in goa_lhs_expr_p the NOP_EXPR addresses aren't equal anymore, which means that the read from *lhs is done before the loop and so is the floating point addition, which means the operation is no longer atomic. Fixed by going through any nops. Tested on x86_64-linux. Ok for trunk/4.2/4.1? 2007-11-09 Jakub Jelinek PR fortran/34020 * gimplify.c (goa_lhs_expr_p): Inside INDIRECT_REF handle unshared nops. * testsuite/libgomp.fortran/pr34020.f90: New test. --- gcc/gimplify.c.jj 2007-11-08 22:50:35.000000000 +0100 +++ gcc/gimplify.c 2007-11-09 08:48:25.000000000 +0100 @@ -5291,8 +5291,22 @@ goa_lhs_expr_p (tree expr, tree addr) == TYPE_MAIN_VARIANT (TREE_TYPE (TREE_OPERAND (expr, 0))))) expr = TREE_OPERAND (expr, 0); - if (TREE_CODE (expr) == INDIRECT_REF && TREE_OPERAND (expr, 0) == addr) - return true; + if (TREE_CODE (expr) == INDIRECT_REF) + { + expr = TREE_OPERAND (expr, 0); + while (expr != addr + && (TREE_CODE (expr) == NOP_EXPR + || TREE_CODE (expr) == CONVERT_EXPR + || TREE_CODE (expr) == NON_LVALUE_EXPR) + && TREE_CODE (expr) == TREE_CODE (addr) + && TYPE_MAIN_VARIANT (TREE_TYPE (expr)) + == TYPE_MAIN_VARIANT (TREE_TYPE (addr))) + { + expr = TREE_OPERAND (expr, 0); + addr = TREE_OPERAND (addr, 0); + } + return expr == addr; + } if (TREE_CODE (addr) == ADDR_EXPR && expr == TREE_OPERAND (addr, 0)) return true; return false; --- libgomp/testsuite/libgomp.fortran/pr34020.f90.jj 2007-11-09 08:56:44.000000000 +0100 +++ libgomp/testsuite/libgomp.fortran/pr34020.f90 2007-11-09 08:56:29.000000000 +0100 @@ -0,0 +1,19 @@ +! PR fortran/34020 +! { dg-do run } + + subroutine atomic_add(lhs, rhs) + real lhs, rhs +!$omp atomic + lhs = rhs + lhs + end + + real lhs, rhs + integer i + lhs = 0 + rhs = 1 +!$omp parallel do num_threads(8) shared(lhs, rhs) + do i = 1, 300000 + call atomic_add(lhs, rhs) + enddo + if (lhs .ne. 300000) call abort + end Jakub