From patchwork Tue Sep 8 10:22:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 1359650 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4Bm1SH0Q9cz9sSn for ; Tue, 8 Sep 2020 20:22:54 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4464F3950C6E; Tue, 8 Sep 2020 10:22:49 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa2.mentor.iphmx.com (esa2.mentor.iphmx.com [68.232.141.98]) by sourceware.org (Postfix) with ESMTPS id CFAA73857C45; Tue, 8 Sep 2020 10:22:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CFAA73857C45 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=Tobias_Burnus@mentor.com IronPort-SDR: /OBjrGKH4OBPrFLZuaiSZXxcqNF+IUQWoPPnVSkJq3tw/NwGMN1lHzfHjUX1fJPB9scX776fPC AnD2l2e1Kau7gis4lGWP108J+QBDfRxGGwmXv/6Ymctms35S2U35eXVrAQDXDx7Sh1w2tmrjRG wBc7S9lzSZv0LtP/wU+/OnzAMEo3tvAyMEsO6LTu0J7o0I2u0Rth5q4xomVfRoehXvS5u/z1o0 Tj3A54Ai23+qH5xPr4gGXzvDkAhyG9epJhI5ihcXPCYTLEMjG/IymDw1Jjw5tL46xrtcUfoA/F +R4= X-IronPort-AV: E=Sophos;i="5.76,405,1592899200"; d="diff'?scan'208";a="52692494" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 08 Sep 2020 02:22:44 -0800 IronPort-SDR: lP9YRQBb1m9zPYnmWtTQFHgw3KmdzUlS6du4akFgRa5J1eF7HVpgoxgUydqBVILL3rLlayN9re MBYRrUoBSOmkDLo1wAAznNkxQNOCgBXcg04aNeTpKf2v69tpZphtRDAoZItyY3sBHWWmbeG62P TjOJtCrrmPDu4gcKE6eDLA0W0x7ctDoOCmYKdXZ+1cgFBh4AIZoif8hXf3bJxyg6xe58mLQcbQ VNv1Qyd5zDst0xyHegj+Hm9iRZLFQVw0gDEUovud9o60RDuo6XOzZpFrGrUTdX2SdCypGsS3fI vSM= To: gcc-patches , fortran , Jakub Jelinek From: Tobias Burnus Subject: [Patch] Fortran: Fixes for OpenMP loop-iter privatization (PRs 95109 + 94690) Message-ID: <9dc63789-fd86-d645-bc04-43c746ae6c98@codesourcery.com> Date: Tue, 8 Sep 2020 12:22:57 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 Content-Language: en-US X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: SVR-IES-MBX-08.mgc.mentorg.com (139.181.222.8) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" This patch fixes all known issues related to loop-iter privatization. This patch removes the code added to gfc_resolve_do_iterator in commit r11-349-gf884bef21cccc05d748fd7869cd641cbb4f6b6bb. I added it to fix some issues in testsuite/libgomp.fortran/pr66199-*.f90 but it turned out that removing no longer causes fails; on the other hand, while r11-349 caused target1.f90 to fail, just removing that changes did not fix it. Digging deeper, I found that for target1.f90's !$omp target teams ... !$omp distribute parallel do simd ... the do-loop's i and j where added to '(target) teams' instead of the 'distribute parallel do simd', causing a middle-end ICE → resolve.c and openmp.c part of the patch. Some testing and looking at dumps additionally showed that for 'target parallel do simd', all loop variables where 'shared' as the wrong function was called in trans-openmp.c. The latter is also the reason that 'combined-if.f90' now has a higher 'omp simd.*if' count. Tested on x86-64-gnu-linux. OK for the trunk and GCC 10? (As r11-349 was not applied to GCC 10, the gfc_resolve_do_iterator change is trunk only.) Tobias ----------------- Mentor Graphics (Deutschland) GmbH, Arnulfstraße 201, 80634 München / Germany Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Alexander Walter Fortran: Fixes for OpenMP loop-iter privatization (PRs 95109 + 94690) This commit also fixes a gfortran.dg/gomp/target1.f90 regression; target1.f90 tests the resolve.c and openmp.c changes. gcc/fortran/ChangeLog: PR fortran/95109 PR fortran/94690 * resolve.c (gfc_resolve_code): Also call gfc_resolve_omp_parallel_blocks for 'distribute parallel do (simd)'. * openmp.c (gfc_resolve_omp_parallel_blocks): Handle it. (gfc_resolve_do_iterator): Remove special code for SIMD, which is not needed. * trans-openmp.c (gfc_trans_omp_target): For TARGET_PARALLEL_DO_SIMD, call simd not do processing function. gcc/testsuite/ChangeLog: PR fortran/95109 PR fortran/94690 * gfortran.dg/gomp/combined-if.f90: Update scan-tree-dump-times for 'omp simd.*if'. * gfortran.dg/gomp/openmp-simd-5.f90: New test. gcc/fortran/openmp.c | 27 ++---------------------- gcc/fortran/resolve.c | 2 ++ gcc/fortran/trans-openmp.c | 8 ++++++- gcc/testsuite/gfortran.dg/gomp/combined-if.f90 | 2 +- gcc/testsuite/gfortran.dg/gomp/openmp-simd-5.f90 | 24 +++++++++++++++++++++ 5 files changed, 36 insertions(+), 27 deletions(-) diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c index d0e516c472d..1efce33e519 100644 --- a/gcc/fortran/openmp.c +++ b/gcc/fortran/openmp.c @@ -5962,6 +5962,8 @@ gfc_resolve_omp_parallel_blocks (gfc_code *code, gfc_namespace *ns) switch (code->op) { + case EXEC_OMP_DISTRIBUTE_PARALLEL_DO: + case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD: case EXEC_OMP_PARALLEL_DO: case EXEC_OMP_PARALLEL_DO_SIMD: case EXEC_OMP_TARGET_PARALLEL_DO: @@ -6047,31 +6049,6 @@ gfc_resolve_do_iterator (gfc_code *code, gfc_symbol *sym, bool add_clause) if (omp_current_ctx->sharing_clauses->contains (sym)) return; - if (omp_current_ctx->is_openmp && omp_current_ctx->code->block) - { - /* SIMD is handled differently and, hence, ignored here. */ - gfc_code *omp_code = omp_current_ctx->code->block; - for ( ; omp_code->next; omp_code = omp_code->next) - switch (omp_code->op) - { - case EXEC_OMP_SIMD: - case EXEC_OMP_DO_SIMD: - case EXEC_OMP_PARALLEL_DO_SIMD: - case EXEC_OMP_DISTRIBUTE_SIMD: - case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD: - case EXEC_OMP_TEAMS_DISTRIBUTE_SIMD: - case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_SIMD: - case EXEC_OMP_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: - case EXEC_OMP_TARGET_TEAMS_DISTRIBUTE_PARALLEL_DO_SIMD: - case EXEC_OMP_TARGET_PARALLEL_DO_SIMD: - case EXEC_OMP_TARGET_SIMD: - case EXEC_OMP_TASKLOOP_SIMD: - return; - default: - break; - } - } - if (! omp_current_ctx->private_iterators->add (sym) && add_clause) { gfc_omp_clauses *omp_clauses = omp_current_ctx->code->ext.omp_clauses; diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index ebf89a9b1f5..f4ce49f8432 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -11722,6 +11722,8 @@ gfc_resolve_code (gfc_code *code, gfc_namespace *ns) omp_workshare_flag = 1; gfc_resolve_omp_parallel_blocks (code, ns); break; + case EXEC_OMP_DISTRIBUTE_PARALLEL_DO: + case EXEC_OMP_DISTRIBUTE_PARALLEL_DO_SIMD: case EXEC_OMP_PARALLEL: case EXEC_OMP_PARALLEL_DO: case EXEC_OMP_PARALLEL_DO_SIMD: diff --git a/gcc/fortran/trans-openmp.c b/gcc/fortran/trans-openmp.c index 7d3365fe7e0..0e1da0426b4 100644 --- a/gcc/fortran/trans-openmp.c +++ b/gcc/fortran/trans-openmp.c @@ -5591,13 +5591,19 @@ gfc_trans_omp_target (gfc_code *code) } break; case EXEC_OMP_TARGET_PARALLEL_DO: - case EXEC_OMP_TARGET_PARALLEL_DO_SIMD: stmt = gfc_trans_omp_parallel_do (code, &block, clausesa); if (TREE_CODE (stmt) != BIND_EXPR) stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0)); else poplevel (0, 0); break; + case EXEC_OMP_TARGET_PARALLEL_DO_SIMD: + stmt = gfc_trans_omp_parallel_do_simd (code, &block, clausesa); + if (TREE_CODE (stmt) != BIND_EXPR) + stmt = build3_v (BIND_EXPR, NULL, stmt, poplevel (1, 0)); + else + poplevel (0, 0); + break; case EXEC_OMP_TARGET_SIMD: stmt = gfc_trans_omp_do (code, EXEC_OMP_SIMD, &block, &clausesa[GFC_OMP_SPLIT_SIMD], NULL_TREE); diff --git a/gcc/testsuite/gfortran.dg/gomp/combined-if.f90 b/gcc/testsuite/gfortran.dg/gomp/combined-if.f90 index 0bb6c28b286..d9e4a26ca0c 100644 --- a/gcc/testsuite/gfortran.dg/gomp/combined-if.f90 +++ b/gcc/testsuite/gfortran.dg/gomp/combined-if.f90 @@ -104,6 +104,6 @@ contains end module ! { dg-final { scan-tree-dump-times "(?n)#pragma omp target.* if\\(" 9 "omplower" } } -! { dg-final { scan-tree-dump-times "(?n)#pragma omp simd.* if\\(" 4 "omplower" { target { ! offload_nvptx } } } } +! { dg-final { scan-tree-dump-times "(?n)#pragma omp simd.* if\\(" 5 "omplower" { target { ! offload_nvptx } } } } ! { dg-final { scan-tree-dump-times "(?n)#pragma omp simd.* if\\(" 7 "omplower" { target { offload_nvptx } } } } ! { dg-final { scan-tree-dump-times "(?n)#pragma omp parallel.* if\\(" 6 "omplower" } } diff --git a/gcc/testsuite/gfortran.dg/gomp/openmp-simd-5.f90 b/gcc/testsuite/gfortran.dg/gomp/openmp-simd-5.f90 new file mode 100644 index 00000000000..b6d4cfa7080 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/openmp-simd-5.f90 @@ -0,0 +1,24 @@ +! { dg-additional-options "-fdump-tree-original" } +! +! Related: +! PR fortran/95109 +! PR fortran/94690 +! +implicit none +integer :: i, j, k, ll +integer :: a +!$omp target parallel do simd collapse(1) + do i = 1, 5 + do j = 1, 5 + do k = 1, 5 + a = a + 1 + end do + do ll = 1, 5 + a = a + 1 + end do + end do + end do +!$omp end target parallel do simd +end + +! { dg-final { scan-tree-dump-times "omp simd linear\\(i:1\\) private\\(j\\) private\\(ll\\) private\\(k\\) collapse\\(1\\)" 1 "original" } }