From patchwork Mon Jun 4 13:27:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 925025 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-479013-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="ZMaSNKzJ"; 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 40zwj76LCrz9ryk for ; Mon, 4 Jun 2018 23:27:38 +1000 (AEST) 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=oSzp0lR/rDuKkXOW1aqBPBi+w0LXpQCF4IrAPhw763D 2QDc4VAo1v5cHGFaiaBpxyASgoXMZmVUbkxOWwRaXOUzWi7EUXI2GtCFxOcb7szA hOuY2YUlBD1YQcTR+sPdESgAcg6WCLV4LgZ7d4l9Md6R/st8dxWYK2TaOzp9E8Vs = 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=ZFtJZLGYBknjAH1YxAwnV1xeBXI=; b=ZMaSNKzJ3+wgOXiqN K2aBgQwMYZX9/DCjQW3UtB/kpxglL0LJGZRycq8y4uK9846rNoPobGnG8bFWQb86 K4zvjdHuOcrgkcve8+k6ycc59cGizSRIWvbU5sZG+4xLiel0b78GTmpaG5Iz+7fT nX0i5bHgwrKZKFGVt0QthHDlIc= Received: (qmail 31423 invoked by alias); 4 Jun 2018 13:27:31 -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 29774 invoked by uid 89); 4 Jun 2018 13:27:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No 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=linear 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, 04 Jun 2018 13:27:29 +0000 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 04E7F3E317 for ; Mon, 4 Jun 2018 13:27:28 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-117-37.ams2.redhat.com [10.36.117.37]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 98CFE60BE0 for ; Mon, 4 Jun 2018 13:27:27 +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 w54DRP17027012 for ; Mon, 4 Jun 2018 15:27:25 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id w54DROHX027011 for gcc-patches@gcc.gnu.org; Mon, 4 Jun 2018 15:27:24 +0200 Date: Mon, 4 Jun 2018 15:27:24 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [gomp5] Allow OpenMP simd loop iter vars to be private or lastprivate Message-ID: <20180604132724.GX14160@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! In OpenMP 5.0, although the simd loop iteration vars are still predetermined linear (for non-collapsed loops or collapse(1)) or lastprivate (collapse>1), one can explicitly make the iteration variable private or lastprivate; especially the former is useful to make it clear nothing needs to be propagated to the original list item. Tested on x86_64-linux, committed to gomp-5_0-branch. 2018-06-04 Jakub Jelinek * gimplify.c (omp_is_private): Allow simd iterator to be lastprivate or private. Fix up diagnostics if linear is used on collapse>1 simd iterator. * gcc.dg/gomp/simd-1.c: New test. * g++.dg/gomp/simd-2.C: New test. * testsuite/libgomp.c-c++-common/simd-1.c: New test. Jakub --- gcc/gimplify.c.jj 2018-05-31 17:16:02.925643457 +0200 +++ gcc/gimplify.c 2018-06-04 12:40:32.232748770 +0200 @@ -7463,18 +7463,9 @@ omp_is_private (struct gimplify_omp_ctx else if ((n->value & GOVD_REDUCTION) != 0) error ("iteration variable %qE should not be reduction", DECL_NAME (decl)); - else if (simd == 0 && (n->value & GOVD_LINEAR) != 0) + else if (simd != 1 && (n->value & GOVD_LINEAR) != 0) error ("iteration variable %qE should not be linear", DECL_NAME (decl)); - else if (simd == 1 && (n->value & GOVD_LASTPRIVATE) != 0) - error ("iteration variable %qE should not be lastprivate", - DECL_NAME (decl)); - else if (simd && (n->value & GOVD_PRIVATE) != 0) - error ("iteration variable %qE should not be private", - DECL_NAME (decl)); - else if (simd == 2 && (n->value & GOVD_LINEAR) != 0) - error ("iteration variable %qE is predetermined linear", - DECL_NAME (decl)); } return (ctx == gimplify_omp_ctxp || (ctx->region_type == ORT_COMBINED_PARALLEL --- gcc/testsuite/gcc.dg/gomp/simd-1.c.jj 2018-06-04 14:32:12.406269289 +0200 +++ gcc/testsuite/gcc.dg/gomp/simd-1.c 2018-06-04 14:13:31.279028667 +0200 @@ -0,0 +1,21 @@ +int a[32], b[32]; + +void +foo (void) +{ + int i, j; + #pragma omp simd linear(i, j) collapse(2) /* { dg-error "iteration variable 'i' should not be linear" } */ + for (i = 0; i < 32; ++i) /* { dg-error "iteration variable 'j' should not be linear" "" { target *-*-* } .-1 } */ + for (j = 0; j < 32; ++j) + a[i] += b[j]; +} + +void +bar (void) +{ + static int i, j; + #pragma omp for simd linear(i, j) collapse(2) /* { dg-error "iteration variable 'i' should not be linear" } */ + for (i = 0; i < 32; ++i) /* { dg-error "iteration variable 'j' should not be linear" "" { target *-*-* } .-1 } */ + for (j = 0; j < 32; ++j) + a[i] += b[j]; +} --- gcc/testsuite/g++.dg/gomp/simd-2.C.jj 2018-06-04 14:32:28.938287583 +0200 +++ gcc/testsuite/g++.dg/gomp/simd-2.C 2018-06-04 14:37:43.931636150 +0200 @@ -0,0 +1,21 @@ +int a[32], b[32]; + +void +foo (void) +{ + int i, j; + #pragma omp simd linear(i, j) collapse(2) // { dg-error "iteration variable 'i' should not be linear" } + for (i = 0; i < 32; ++i) // { dg-error "iteration variable 'j' should not be linear" "" { target *-*-* } .-1 } + for (j = 0; j < 32; ++j) + a[i] += b[j]; +} + +void +bar (void) +{ + static int i, j; + #pragma omp for simd linear(i, j) collapse(2) // { dg-error "iteration variable 'i' should not be linear" "" { target *-*-* } .+1 } + for (i = 0; i < 32; ++i) // { dg-error "iteration variable 'j' should not be linear" } + for (j = 0; j < 32; ++j) + a[i] += b[j]; +} --- libgomp/testsuite/libgomp.c-c++-common/simd-1.c.jj 2018-06-04 14:18:27.803356796 +0200 +++ libgomp/testsuite/libgomp.c-c++-common/simd-1.c 2018-06-04 14:19:02.968395710 +0200 @@ -0,0 +1,71 @@ +// { dg-do run } +// { dg-additional-options "-msse2" { target sse2_runtime } } +// { dg-additional-options "-mavx" { target avx_runtime } } + +#define N 1024 +int a[N], b[N]; + +int +f1 (void) +{ + int i; + #pragma omp simd private (i) + for (i = 0; i < N; i++) + a[i] = b[i] * 2; + #pragma omp simd lastprivate (i) + for (i = 0; i < N; i++) + a[i] += b[i] * 2; + return i; +} + +int +f2 (void) +{ + int i, j; + #pragma omp simd private (i), collapse (2), lastprivate (j) + for (i = 0; i < 32; i++) + for (j = 0; j < 32; ++j) + a[i * 32 + j] += b[i * 32 + j] * 2; + return j; +} + +int +f3 (void) +{ + static int i; + #pragma omp for simd private (i) + for (i = 0; i < N; ++i) + a[i] = b[i] * 2; + #pragma omp for simd lastprivate (i) + for (i = 0; i < N; ++i) + a[i] += b[i] * 2; + return i; +} + +int +f4 (void) +{ + static int i, j; + #pragma omp for simd private (i)collapse (2)lastprivate (j) + for (i = 0; i < 32; ++i) + for (j = 0; j < 32; j++) + a[i * 32 + j] += b[i * 32 + j] * 2; + return j; +} + +int +main () +{ + int i; + for (i = 0; i < N; ++i) + a[i] = b[i] = i; + if (f1 () != 1024 || f2 () != 32) + __builtin_abort (); + #pragma omp parallel num_threads(4) + if (f3 () != 1024 || f4 () != 32) + __builtin_abort (); + for (i = 0; i < N; ++i) + if (a[i] != 6 * i || b[i] != i) + __builtin_abort (); + return 0; +}