From patchwork Mon Feb 24 11:21:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 1243004 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=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-519970-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha1 header.s=default header.b=EfhNCjKG; 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 48R05L0FTdz9sP7 for ; Mon, 24 Feb 2020 22:21:55 +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:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=cV9UVnT6D3YfZ/Mfb810wvurCLDiWONI/q6rSLAIKAaBCC7joU GcR+8RqWXNmUiggm+1V10c+dA7GYCTAADJxj9am8AeMIT8O+ms2HlrGaSSki63ud 17Nxyywlx4PPBPMpU4Q6YptdiS3jPq+q6k6xMs/FJzMwfcm2XPyLSGyuc= 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:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=IWyN2ru27UcRCrZSnBdSdxfdNwA=; b=EfhNCjKGBDhPCO4yxy48 e76HC8raZ7absdIR2EMTU2HVNg10RcK9z6gTozwSm0fpTiOxS6Wli70IhY0rbti/ mUBmM+BapFbYPtw2DZCr006g3E5zWVEOmzQJdnZ8vg4JvywKl7IR2qNSc6UZgbDl b1LFUwWbm+yZLOs7EHe8l6Q= Received: (qmail 4379 invoked by alias); 24 Feb 2020 11:21: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 4366 invoked by uid 89); 24 Feb 2020 11:21:48 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.6 required=5.0 tests=AWL, BAYES_00, GARBLED_SUBJECT, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=collapse X-HELO: esa1.mentor.iphmx.com Received: from esa1.mentor.iphmx.com (HELO esa1.mentor.iphmx.com) (68.232.129.153) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 24 Feb 2020 11:21:37 +0000 IronPort-SDR: TOj5+20CD/fFGr0rzRJADm4SOLC2YtA991dfq591wAbjv/8rGLh754VwxtXHFnLYrY4kNj9M/O vIZtlzBeALfPCdVLW9ypI3gOz7FFLd072zJpK5vzlbpzZe8WX4LG+tT1I7Emdm56VeUH6/1qbJ F5pXXp89EohkJnTieSIBIUI0cnKDr+DtaTul5vF9VNaVnEPL9hnm43rl79qxUG1SSRYiVb2+lp B6F4A88keWyhz15NHPCgnrnhClgJUKJSkp/+QsLsTpmJFLdMPkprVROhQvjpHjuoIec4xVpmwc VbU= Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa1.mentor.iphmx.com with ESMTP; 24 Feb 2020 03:21:36 -0800 IronPort-SDR: dfEl+JJtLbT0mcoPI1G6lwWkMWUsL1fvqtQ4W/YL0DTvu2JNHC+nXSAe7p+IFdWSV8rublNma9 OQiucMK2PqFI/4mIq0XHTzzY7q4yn8ZsJSKwL0kWT2j6ctrhDIw4UZN0TKy27dAsSAe9eHKq7Z D0sbC6ZICbFNSLyk7oElDy4T5hW5/CmBFfcjlUzKDTS1S2+q7LpfMAB5Yc6mc5651+pci2JuxE WY3BXJnqrh52uTFkA5/0Y5vVGjGpwBiqoUGeYkMXlstQhwNKPWy9mYUplEj6AnVjkyYLnCqLTr il0= To: gcc-patches CC: fortran , Thomas Schwinge From: Tobias Burnus Subject: =?utf-8?q?=5BPatch=2C_Fortran=2C_committed=5D_OpenACC_tile_claus?= =?utf-8?q?e_=E2=80=93_apply_exit/cycle_checks_=28PR_93552=29?= Message-ID: <5fe46ee6-7c43-7256-a238-c04836d5e7a9@codesourcery.com> Date: Mon, 24 Feb 2020 12:21:29 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 X-IsSubscribed: yes All is about OpenACC. First, when testing, I found out that "kernels loop" wasn't checked for – only serial/parallel loop and an "acc loop". For nested loops, besides using the "collapse" clause also the "tile" clause can be used. Internally, those are processed identically (on the FE side) but "tile" wins if both are specified. Hence: NOTE: I only do check of "tile" – if tile is for a nest level of n while collapse is for a nest level > n, invalid use related to collapse, only, are not detected. That's in line with the later implementation where "tile" has a higher priority. For "collapse" exits from the loop and "cycle" to any but the innermost loop was ready rejected – for "tile" this was not checked for – and, hence, accepted. As the rest of the code wasn't prepared for it, it lead to an ICE. In my understanding of the OpenACC spec ("tightly nested loop", semantic) "tile" and "collapse" have the same restriction such that the attached test case is invalid. (However, the bug reported marked it as 'ice-on-valid-code'.) Committed as Rev. r10-6808-g2bd8c3ff3511df8781dd9f3777efab20572d29ab Cheers, Tobias commit 2bd8c3ff3511df8781dd9f3777efab20572d29ab Author: Tobias Burnus Date: Mon Feb 24 12:18:04 2020 +0100 OpenACC tile clause – apply exit/cycle checks (PR 93552) PR fortran/93552 * match.c (match_exit_cycle): With OpenACC, check the kernels loop directive and tile clause as well. PR fortran/93552 * gfortran.dg/goacc/tile-4.f90: New. --- gcc/fortran/ChangeLog | 6 ++++++ gcc/fortran/match.c | 25 ++++++++++++++++++++----- gcc/testsuite/ChangeLog | 7 ++++++- gcc/testsuite/gfortran.dg/goacc/tile-4.f90 | 27 +++++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 6 deletions(-) diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 1ed6a97366e..94ceb5c8aa3 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2020-02-24 Tobias Burnus + + PR fortran/93552 + * match.c (match_exit_cycle): With OpenACC, check the kernels loop + directive and tile clause as well. + 2020-02-23 Thomas Koenig PR fortran/93889 diff --git a/gcc/fortran/match.c b/gcc/fortran/match.c index e4d52245976..17196eb1ae6 100644 --- a/gcc/fortran/match.c +++ b/gcc/fortran/match.c @@ -2878,6 +2878,7 @@ match_exit_cycle (gfc_statement st, gfc_exec_op op) && o != NULL && o->state == COMP_OMP_STRUCTURED_BLOCK && (o->head->op == EXEC_OACC_LOOP + || o->head->op == EXEC_OACC_KERNELS_LOOP || o->head->op == EXEC_OACC_PARALLEL_LOOP || o->head->op == EXEC_OACC_SERIAL_LOOP)) { @@ -2887,9 +2888,20 @@ match_exit_cycle (gfc_statement st, gfc_exec_op op) || o->head->next->op == EXEC_DO_WHILE) && o->previous != NULL && o->previous->tail->op == o->head->op); - if (o->previous->tail->ext.omp_clauses != NULL - && o->previous->tail->ext.omp_clauses->collapse > 1) - collapse = o->previous->tail->ext.omp_clauses->collapse; + if (o->previous->tail->ext.omp_clauses != NULL) + { + /* Both collapsed and tiled loops are lowered the same way, but are not + compatible. In gfc_trans_omp_do, the tile is prioritized. */ + if (o->previous->tail->ext.omp_clauses->tile_list) + { + collapse = 0; + gfc_expr_list *el = o->previous->tail->ext.omp_clauses->tile_list; + for ( ; el; el = el->next) + ++collapse; + } + else if (o->previous->tail->ext.omp_clauses->collapse > 1) + collapse = o->previous->tail->ext.omp_clauses->collapse; + } if (st == ST_EXIT && cnt <= collapse) { gfc_error ("EXIT statement at %C terminating !$ACC LOOP loop"); @@ -2897,8 +2909,11 @@ match_exit_cycle (gfc_statement st, gfc_exec_op op) } if (st == ST_CYCLE && cnt < collapse) { - gfc_error ("CYCLE statement at %C to non-innermost collapsed" - " !$ACC LOOP loop"); + gfc_error (o->previous->tail->ext.omp_clauses->tile_list + ? G_("CYCLE statement at %C to non-innermost tiled" + " !$ACC LOOP loop") + : G_("CYCLE statement at %C to non-innermost collapsed" + " !$ACC LOOP loop")); return MATCH_ERROR; } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 13c1a132cc1..bd50ffdbd68 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2020-02-24 Tobias Burnus + + PR fortran/93552 + * gfortran.dg/goacc/tile-4.f90: New. + 2020-02-24 Prathamesh Kulkarni Kugan Vivekandarajah @@ -43,7 +48,7 @@ 2020-02-21 Jan Hubicka Richard Biener - PR tree-optimization/93586 + PR tree-optimization/93586 * gcc.dg/torture/pr93586.c: New testcase. 2020-02-21 Martin Jambor diff --git a/gcc/testsuite/gfortran.dg/goacc/tile-4.f90 b/gcc/testsuite/gfortran.dg/goacc/tile-4.f90 new file mode 100644 index 00000000000..86c22df9b66 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/goacc/tile-4.f90 @@ -0,0 +1,27 @@ +! { dg-do compile } +! +! Contributed by G. Steinmetz +! +! PR fortran/93552 +! only collapsed an not tile was checked: +program p + integer :: i, j + !$acc parallel loop tile(2,2) + outer: do i = 1, 8 + do j = 1, 8 + exit ! { dg-error "statement at .1. terminating ..ACC LOOP loop" } + cycle outer ! { dg-error "to non-innermost tiled" } + end do + end do outer +end + +! Kernels loop was missing the check: +subroutine test + !$acc kernels loop collapse(2) + outer: do i = 1, 4 + do j = 1, 4 + exit ! { dg-error "statement at .1. terminating ..ACC LOOP loop" } + cycle outer ! { dg-error "to non-innermost collapsed" } + end do + end do outer +end