From patchwork Wed Mar 8 17:25:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 736670 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 3vdgRB1hjxz9s8G for ; Thu, 9 Mar 2017 04:25:57 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="R2vGQGYE"; 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=IogCS2H5jYqTAg1+QvNprRmX0tPwyZv4PMFeX+4fYkp 41A1yLWnIFCwGv2hSxj1EJn1T4moHMRZzL+Vjucazcm8FdUrpSr/McJSeKIh8m0p 7j+y49Jnx5ZBHj8O8LNZ/iiTPpTyO9v7gGFogq/zKr/8MSCLf164TdxNSPrhkBgk = 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=SY+cjJ4vi5UzdT58G+bf7E4mUMQ=; b=R2vGQGYEnaYHBkk7o RP5lKx/NePSpE0Liwq/Mv6u8QHAztlNfhQmPikTyVMccS/QKTrMcvpgf6TWJGD6U OSxWiaSc4FRF3F6Fd4UwmHcbP4rfMPVRT5QW5zMCBqiENMvUapTqKFTJPzSPhWJC MJ88mn6+uPOxKNdLZWk7ly+j1E= Received: (qmail 27574 invoked by alias); 8 Mar 2017 17:25:48 -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 27560 invoked by uid 89); 8 Mar 2017 17:25:47 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-15.9 required=5.0 tests=BAYES_00, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=6x 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; Wed, 08 Mar 2017 17:25:45 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1539380475 for ; Wed, 8 Mar 2017 17:25:46 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-117-76.ams2.redhat.com [10.36.117.76]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v28HPisT011308 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO) for ; Wed, 8 Mar 2017 12:25:45 -0500 Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id v28HPgFG031131 for ; Wed, 8 Mar 2017 18:25:42 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id v28HPfe6031130 for gcc-patches@gcc.gnu.org; Wed, 8 Mar 2017 18:25:41 +0100 Date: Wed, 8 Mar 2017 18:25:41 +0100 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [committed] Fix taskloop handling inside of parallel construct body (PR c/79940) Message-ID: <20170308172541.GB22703@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! We split OMP_TASKLOOP into 3 constructs, two GIMPLE_OMP_FOR with GIMPLE_OMP_PARALLEL sandwiched in between them, so that it is possible to compute number of iterations etc. before calling GOMP_taskloop*. Using the original iterator in the outer gfor doesn't play very well if the taskloop region is nested in other OpenMP regions like parallel. This patch just creates a temporary for that. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk so far, queued for 6.x. 2017-03-08 Jakub Jelinek PR c/79940 * gimplify.c (gimplify_omp_for): Replace index var in outer taskloop statement with an artificial variable and add OMP_CLAUSE_PRIVATE clause for it. * testsuite/libgomp.c/pr79940.c: New test. Jakub --- gcc/gimplify.c.jj 2017-02-21 09:03:57.000000000 +0100 +++ gcc/gimplify.c 2017-03-08 10:06:11.926501447 +0100 @@ -10232,8 +10232,9 @@ gimplify_omp_for (tree *expr_p, gimple_s gimple_omp_for_set_combined_into_p (gfor, true); for (i = 0; i < (int) gimple_omp_for_collapse (gfor); i++) { - t = unshare_expr (gimple_omp_for_index (gfor, i)); - gimple_omp_for_set_index (gforo, i, t); + tree type = TREE_TYPE (gimple_omp_for_index (gfor, i)); + tree v = create_tmp_var (type); + gimple_omp_for_set_index (gforo, i, v); t = unshare_expr (gimple_omp_for_initial (gfor, i)); gimple_omp_for_set_initial (gforo, i, t); gimple_omp_for_set_cond (gforo, i, @@ -10241,7 +10242,13 @@ gimplify_omp_for (tree *expr_p, gimple_s t = unshare_expr (gimple_omp_for_final (gfor, i)); gimple_omp_for_set_final (gforo, i, t); t = unshare_expr (gimple_omp_for_incr (gfor, i)); + gcc_assert (TREE_OPERAND (t, 0) == gimple_omp_for_index (gfor, i)); + TREE_OPERAND (t, 0) = v; gimple_omp_for_set_incr (gforo, i, t); + t = build_omp_clause (input_location, OMP_CLAUSE_PRIVATE); + OMP_CLAUSE_DECL (t) = v; + OMP_CLAUSE_CHAIN (t) = gimple_omp_for_clauses (gforo); + gimple_omp_for_set_clauses (gforo, t); } gimplify_seq_add_stmt (pre_p, gforo); } --- libgomp/testsuite/libgomp.c/pr79940.c.jj 2017-03-08 10:47:26.179154442 +0100 +++ libgomp/testsuite/libgomp.c/pr79940.c 2017-03-08 10:46:46.000000000 +0100 @@ -0,0 +1,47 @@ +/* PR c/79940 */ + +int +main () +{ + int i, j, l, m; + int a[10000], b[10000], c[10000]; + for (i = 0; i < 10000; i++) + { + a[i] = i; + b[i] = i & 31; + } +#pragma omp parallel shared(a, b, c) +#pragma omp single +#pragma omp taskloop shared(a, b, c) + for (i = 0; i < 10000; i++) + c[i] = a[i] + b[i]; +#pragma omp parallel +#pragma omp single + { + #pragma omp taskloop shared(a, b, c) lastprivate (i) + for (i = 0; i < 10000; i++) + c[i] += a[i] + b[i]; + l = i; + } +#pragma omp parallel +#pragma omp single +#pragma omp taskloop shared(a, b, c) collapse(2) + for (i = 0; i < 100; i++) + for (j = 0; j < 100; j++) + c[i * 100 + j] += a[i * 100 + j] + b[i * 100 + j]; +#pragma omp parallel +#pragma omp single + { + #pragma omp taskloop shared(a, b, c) lastprivate (i, j) + for (i = 0; i < 100; i++) + for (j = 0; j < 100; j++) + c[i * 100 + j] += a[i * 100 + j] + b[i * 100 + j]; + m = i * 100 + j; + } + for (i = 0; i < 10000; i++) + if (a[i] != i || b[i] != (i & 31) || c[i] != 4 * i + 4 * (i & 31)) + __builtin_abort (); + if (l != 10000 || m != 10100) + __builtin_abort (); + return 0; +}