From patchwork Mon May 22 18:58:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 765555 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wWnxf6QvLz9s0m for ; Tue, 23 May 2017 04:58:45 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="TZmoSMom"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:reply-to:mime-version:content-type; q=dns; s=default; b=RCp2NZ70jc1wVvGro2//bYvjzVMROSqEUTSTv18WCCt 0eGo+qc1sHt2CXuIym/u2c+GFnbMYYtt7yzsuGH/mQcsBG1Fs6Wb6PA8uMAaao9j vblE0Qcb+XwMCLs/42JyK/BW419S3ljTKdoQolbukjNYVOzwii4phHeqjDr7MWYQ = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:reply-to:mime-version:content-type; s=default; bh=4MkqsEPfxAe10qbaW57oDpnW93M=; b=TZmoSMomjcHfTh36M Nq417ElqTOATcWJRbrwj5Ma5v/SrVPhslb+tDYvQVeph/hiEToRErD8VQqoCDfVl h0nysCZR2hM/vMW+vVnejQt/ZcIcKX8U9e+SS9OW2iS3nVgu7SJFiklcIT52e/Y3 IDYnT1pSTZPisYQSOlazOF39DA= Received: (qmail 24842 invoked by alias); 22 May 2017 18:58:33 -0000 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 Received: (qmail 24832 invoked by uid 89); 22 May 2017 18:58:33 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=orphaned X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 22 May 2017 18:58:31 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BCA4580C20 for ; Mon, 22 May 2017 18:58:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com BCA4580C20 Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx02.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=jakub@redhat.com DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com BCA4580C20 Received: from tucnak.zalov.cz (ovpn-116-29.ams2.redhat.com [10.36.116.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6677C173AD for ; Mon, 22 May 2017 18:58:33 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id v4MIwUrr024898 for ; Mon, 22 May 2017 20:58:31 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id v4MIwTKp024897 for gcc-patches@gcc.gnu.org; Mon, 22 May 2017 20:58:29 +0200 Date: Mon, 22 May 2017 20:58:29 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [committed] Fix OpenMP array reduction handling in orphaned workshare (PR middle-end/80853) Message-ID: <20170522185829.GF8499@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.7.1 (2016-10-04) X-IsSubscribed: yes Hi! For pointer based array sections, we are not requiring the pointer to be shared in outer context and it might be not shared (e.g. function argument or just a private pointer initialized to point to something shared etc.), which is right, but we shouldn't require it during lowering either. This patch fixes ICE on it. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk, queued for release branches. 2017-05-22 Jakub Jelinek PR middle-end/80853 * omp-low.c (lower_reduction_clauses): Pass OMP_CLAUSE_PRIVATE as last argument to build_outer_var_ref for pointer bases of array section reductions. * testsuite/libgomp.c/pr80853.c: New test. Jakub --- gcc/omp-low.c.jj 2017-04-21 08:14:29.436790613 +0200 +++ gcc/omp-low.c 2017-05-22 11:34:51.085746641 +0200 @@ -5140,15 +5140,25 @@ lower_reduction_clauses (tree clauses, g if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION) continue; + enum omp_clause_code ccode = OMP_CLAUSE_REDUCTION; orig_var = var = OMP_CLAUSE_DECL (c); if (TREE_CODE (var) == MEM_REF) { var = TREE_OPERAND (var, 0); if (TREE_CODE (var) == POINTER_PLUS_EXPR) var = TREE_OPERAND (var, 0); - if (TREE_CODE (var) == INDIRECT_REF - || TREE_CODE (var) == ADDR_EXPR) + if (TREE_CODE (var) == ADDR_EXPR) var = TREE_OPERAND (var, 0); + else + { + /* If this is a pointer or referenced based array + section, the var could be private in the outer + context e.g. on orphaned loop construct. Pretend this + is private variable's outer reference. */ + ccode = OMP_CLAUSE_PRIVATE; + if (TREE_CODE (var) == INDIRECT_REF) + var = TREE_OPERAND (var, 0); + } orig_var = var; if (is_variable_sized (var)) { @@ -5162,7 +5172,7 @@ lower_reduction_clauses (tree clauses, g new_var = lookup_decl (var, ctx); if (var == OMP_CLAUSE_DECL (c) && omp_is_reference (var)) new_var = build_simple_mem_ref_loc (clause_loc, new_var); - ref = build_outer_var_ref (var, ctx); + ref = build_outer_var_ref (var, ctx, ccode); code = OMP_CLAUSE_REDUCTION_CODE (c); /* reduction(-:var) sums up the partial results, so it acts --- libgomp/testsuite/libgomp.c/pr80853.c.jj 2017-05-22 11:28:50.060287195 +0200 +++ libgomp/testsuite/libgomp.c/pr80853.c 2017-05-22 11:28:29.000000000 +0200 @@ -0,0 +1,29 @@ +/* PR middle-end/80853 */ +/* { dg-do run } */ + +__attribute__((noinline, noclone)) void +foo (int *p) +{ + #pragma omp for reduction(+:p[:4]) + for (int i = 0; i < 64; i++) + { + p[0] += i; + p[1] += i / 2; + p[2] += 2 * i; + p[3] += 3 * i; + } +} + +int +main () +{ + int p[4] = { 0, 0, 0, 0 }; + #pragma omp parallel + foo (p); + if (p[0] != 63 * 64 / 2 + || p[1] != 31 * 32 + || p[2] != 63 * 64 + || p[3] != 3 * 63 * 64 / 2) + __builtin_abort (); + return 0; +}