From patchwork Tue Oct 9 13:08:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 981202 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-487204-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="P0bJQVWT"; dkim-atps=neutral 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 42TyG76QXcz9s89 for ; Wed, 10 Oct 2018 00:08:15 +1100 (AEDT) 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=Z9bV1FJdEcTfD2vr3paT3XVrImMLvEdV2Pvx5fKk8SW Z/aXCw1bqZ+ej+ce4b/P5lxgjUVO93BQ/aR440NmaT+XIN2vyagmBSg8LEDVlCry FWgGLdzx4MxC2MLwkVrWxO99egBOgvbE43L3t/nUQW4d9+ZlJW/MEokhFjLHCbVs = 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=rAWDHt0e4RPHg+iVLPD3l4vl7Hs=; b=P0bJQVWTiZtHH/Vjo /MlZ0w40ugXuKP0ScWOHTC4EeNPYSwcXyAQOg+R/tP01ZBRijGNqKckwGUoE6ekF j9stfBgKHyJg6M6JaupgkI50cpspLCKnTtxyKLhqDoyr9CT064WmqSnzBCj/mEUc YYr624vTd5nR3iwCLvk96pZ3as= Received: (qmail 116809 invoked by alias); 9 Oct 2018 13:08:07 -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 116799 invoked by uid 89); 9 Oct 2018 13:08:06 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= 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; Tue, 09 Oct 2018 13:08:05 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 264C59D42C for ; Tue, 9 Oct 2018 13:08:04 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-116-82.ams2.redhat.com [10.36.116.82]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C15226F43B for ; Tue, 9 Oct 2018 13:08:03 +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 w99D81tR028816 for ; Tue, 9 Oct 2018 15:08:02 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id w99D80HU028815 for gcc-patches@gcc.gnu.org; Tue, 9 Oct 2018 15:08:00 +0200 Date: Tue, 9 Oct 2018 15:08:00 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [gomp5] Fix handling of task_reduction with variable length array sections Message-ID: <20181009130800.GO11625@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.2 (2017-12-15) X-IsSubscribed: yes Hi! As the following testcase additions show, even the TYPE_MAX_VALUE var needs to be forced into temporary if it is a user variable, otherwise if that variable is changed by the user before taskgroup ends, we don't handle it correctly. In addition to that, this patch removes useless NULL second argument from create_tmp_var, forgot we do have a default argument here. Tested on x86_64-linux, committed to gomp-5_0-branch. 2018-10-09 Jakub Jelinek * omp-low.c (lower_omp_task_reductions): Force TYPE_MAX_VALUE into a temporary in the start sequence and even when it is a decl already. * omp-low.c (lower_rec_input_clauses, lower_reduction_clauses, lower_omp_task_reductions): Remove second argument create_tmp_var if it is NULL. * gimplify.c (gimplify_omp_depend): Likewise. * testsuite/libgomp.c-c++-common/task-reduction-5.c: Add further test to verify the array bound var can be changed in taskgroup. Jakub --- gcc/omp-low.c.jj 2018-10-08 17:30:42.147353172 +0200 +++ gcc/omp-low.c 2018-10-09 14:19:54.672380754 +0200 @@ -4091,7 +4091,7 @@ lower_rec_input_clauses (tree clauses, g gimple_seq_add_stmt (ilist, g); } - tree y1 = create_tmp_var (ptype, NULL); + tree y1 = create_tmp_var (ptype); gimplify_assign (y1, y, ilist); tree i2 = NULL_TREE, y2 = NULL_TREE; tree body2 = NULL_TREE, end2 = NULL_TREE; @@ -4102,14 +4102,14 @@ lower_rec_input_clauses (tree clauses, g size_int (task_reduction_cnt_full + task_reduction_cntorig - 1), NULL_TREE, NULL_TREE); - y3 = create_tmp_var (ptype, NULL); + y3 = create_tmp_var (ptype); gimplify_assign (y3, ref, ilist); } else if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) || is_simd) { if (pass != 3) { - y2 = create_tmp_var (ptype, NULL); + y2 = create_tmp_var (ptype); gimplify_assign (y2, y, ilist); } if (is_simd || OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c)) @@ -4126,23 +4126,23 @@ lower_rec_input_clauses (tree clauses, g if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) && OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c)) { - y3 = create_tmp_var (ptype, NULL); + y3 = create_tmp_var (ptype); gimplify_assign (y3, unshare_expr (ref), ilist); } if (is_simd) { - y4 = create_tmp_var (ptype, NULL); + y4 = create_tmp_var (ptype); gimplify_assign (y4, ref, dlist); } } } - tree i = create_tmp_var (TREE_TYPE (v), NULL); + tree i = create_tmp_var (TREE_TYPE (v)); gimplify_assign (i, build_int_cst (TREE_TYPE (v), 0), ilist); tree body = create_artificial_label (UNKNOWN_LOCATION); gimple_seq_add_stmt (ilist, gimple_build_label (body)); if (y2) { - i2 = create_tmp_var (TREE_TYPE (v), NULL); + i2 = create_tmp_var (TREE_TYPE (v)); gimplify_assign (i2, build_int_cst (TREE_TYPE (v), 0), dlist); body2 = create_artificial_label (UNKNOWN_LOCATION); end2 = create_artificial_label (UNKNOWN_LOCATION); @@ -5603,7 +5603,7 @@ lower_reduction_clauses (tree clauses, g tree d = OMP_CLAUSE_DECL (c); tree type = TREE_TYPE (d); tree v = TYPE_MAX_VALUE (TYPE_DOMAIN (type)); - tree i = create_tmp_var (TREE_TYPE (v), NULL); + tree i = create_tmp_var (TREE_TYPE (v)); tree ptype = build_pointer_type (TREE_TYPE (type)); tree bias = TREE_OPERAND (d, 1); d = TREE_OPERAND (d, 0); @@ -5667,10 +5667,10 @@ lower_reduction_clauses (tree clauses, g } new_var = fold_convert_loc (clause_loc, ptype, new_var); ref = fold_convert_loc (clause_loc, ptype, ref); - tree m = create_tmp_var (ptype, NULL); + tree m = create_tmp_var (ptype); gimplify_assign (m, new_var, stmt_seqp); new_var = m; - m = create_tmp_var (ptype, NULL); + m = create_tmp_var (ptype); gimplify_assign (m, ref, stmt_seqp); ref = m; gimplify_assign (i, build_int_cst (TREE_TYPE (v), 0), stmt_seqp); @@ -6896,22 +6896,24 @@ lower_omp_task_reductions (omp_context * { tree type = TREE_TYPE (new_var); tree v = TYPE_MAX_VALUE (TYPE_DOMAIN (type)); - tree i = create_tmp_var (TREE_TYPE (v), NULL); + tree i = create_tmp_var (TREE_TYPE (v)); tree ptype = build_pointer_type (TREE_TYPE (type)); if (DECL_P (v)) { v = maybe_lookup_decl_in_outer_ctx (v, ctx); - gimplify_expr (&v, end, NULL, is_gimple_val, fb_rvalue); + tree vv = create_tmp_var (TREE_TYPE (v)); + gimplify_assign (vv, v, start); + v = vv; } ref = build4 (ARRAY_REF, pointer_sized_int_node, avar, size_int (7 + cnt * 3), NULL_TREE, NULL_TREE); new_var = build_fold_addr_expr (new_var); new_var = fold_convert (ptype, new_var); ref = fold_convert (ptype, ref); - tree m = create_tmp_var (ptype, NULL); + tree m = create_tmp_var (ptype); gimplify_assign (m, new_var, end); new_var = m; - m = create_tmp_var (ptype, NULL); + m = create_tmp_var (ptype); gimplify_assign (m, ref, end); ref = m; gimplify_assign (i, build_int_cst (TREE_TYPE (v), 0), end); --- gcc/gimplify.c.jj 2018-08-02 17:59:48.980047042 +0200 +++ gcc/gimplify.c 2018-10-09 14:13:25.243928507 +0200 @@ -7736,7 +7736,7 @@ gimplify_omp_depend (tree *list_p, gimpl cnts[i] = cnts[i - 1]; continue; } - cnts[i] = create_tmp_var (sizetype, NULL); + cnts[i] = create_tmp_var (sizetype); if (i == 0) g = gimple_build_assign (cnts[i], size_int (is_old ? 2 : 5)); else --- libgomp/testsuite/libgomp.c-c++-common/task-reduction-5.c.jj 2018-10-08 17:22:33.200531039 +0200 +++ libgomp/testsuite/libgomp.c-c++-common/task-reduction-5.c 2018-10-09 13:56:38.907851288 +0200 @@ -7,49 +7,58 @@ void abort (void); int *q; void -bar (int *p, int *r, int s) +bar (int *p, int *r, int *t, int s, __SIZE_TYPE__ u) { - #pragma omp task in_reduction (*: p[0], q[0], r[s - 1]) + #pragma omp task in_reduction (*: p[0], q[0], r[s - 1], t[0:u + 1]) { *p *= 4; *q *= 5; r[s - 1] *= 6; + t[0] *= 8; + t[1] *= 9; } } void -foo (int *p, int *r, int s) +foo (int *p, int *r, int *t, int s, __SIZE_TYPE__ u) { int *p2 = p; - #pragma omp taskgroup task_reduction (*: p[0], q[0], r[s]) + #pragma omp taskgroup task_reduction (*: p[0], q[0], r[s], t[0:u + 1]) { p = (int *) 0; s++; - bar (p2, r, s); + bar (p2, r, t, s, u); r++; #pragma omp taskwait - #pragma omp task in_reduction (*: p2[0], q[0], r[s - 2]) + #pragma omp task in_reduction (*: p2[0], q[0], r[s - 2], t[0:u + 1]) { *p2 *= 2; *q *= 3; r[s - 2] *= 7; + t[0] *= 10; + t[1] *= 11; } + u = __SIZE_MAX__ / 4; s++; p2 = (int *) 0; q = (int *) 0; r = (int *) 0; + t = (int *) 0; } } int main () { - int a = 1, b = 1, c[2] = { 1, 0 }; + int a = 1, b = 1, c[2] = { 1, 0 }, d[3] = { 1, 1, -1 }; + volatile int zero; + zero = 0; q = &b; #pragma omp parallel num_threads (2) #pragma omp master - foo (&a, &c[0], 0); - if (a != 8 || b != 15 || c[0] != 42 || c[1] != 0) + foo (&a, &c[0], &d[0], zero, zero + 1); + if (a != 8 || b != 15 || c[0] != 42 || c[1] != 0 + || d[0] != 80 || d[1] != 99 || d[2] != -1) abort (); return 0; }