From patchwork Tue Aug 16 14:06:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 557 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6a10:38f:b0:2d5:3c95:9e21 with SMTP id 15csp2028397pxh; Tue, 16 Aug 2022 07:07:02 -0700 (PDT) X-Google-Smtp-Source: AA6agR4D9AfqqKS5VMepHVvosLQ3jSZhGsYMICzjco+PxZOoLveRMwQFA0Lg7tKe1oWRTPZ7HdxK X-Received: by 2002:a17:907:948f:b0:731:3f2e:8916 with SMTP id dm15-20020a170907948f00b007313f2e8916mr13884568ejc.442.1660658822261; Tue, 16 Aug 2022 07:07:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660658822; cv=none; d=google.com; s=arc-20160816; b=oS9+BvFRqyZgER9Jh8AOMMULFVAL2Pjg+CVmhiLg3CBWWSYJa9TmlevmuuKIZKw71v 2i0Sk5yN4DRYZ9qPu2k8Q0NcYh/OMFpZ751RagNHP9V2fO5DRTm4GYum/e18CuRGK2qK lDECfXenWFxZKyBQLxelumMmC0Q62dwUmsg5OL4la+LC6dsxHDxThr0JNmnziTg9M0aD DrPsbwlCNnjquX3HfhxL4JryJOlMC1gSLhlFTjHeQk9JRhK+gXcTuCj4HAfUTWXTNy2C wWFUvngYMS19XU54p1IxNrRiUuV0LR2+PHjMi/CiHICpCdu/M1irHqaw13HQ6M0SPxab L1ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:from:to :content-language:user-agent:mime-version:date:message-id :ironport-sdr:dmarc-filter:delivered-to; bh=HrngVEPFNEm3jTmNtJgRNuJBody9ajlg9bW5EIQqb/E=; b=gb1v+1w03Bycx8qERyBTX312pStKXtjTOS8Pk5bGkcMdvE8R0G4yh7eCCFsAxhBnoE U+EbMXFMHr/BWGKxaJ9/wIVOJ0lu20f/w4AJL5eMfAe8EyQKfzYCHRhCHWUD6OljOi4w whnRwAHsovbWMUlCdcsc0hWkN2yGtyM4bDl/qyfE7UtBK+dCAPTfYNFS63KgtaUIBcBb jMvD8Bu+pNyYaqoOJqweROiS+hESdqL23nqmDjic8+mteVQpW9GjT6DA/8RVkAoeb3D4 KgLd8kYG4zuLy6frIuYNGzW4ALKzR62QOGEDQdameQ14mdJm327QYhRr57OjRbu6pOYS iNsQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id hy16-20020a1709068a7000b007308bc0ecaesi8043480ejc.429.2022.08.16.07.07.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Aug 2022 07:07:02 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F3D783857B9C for ; Tue, 16 Aug 2022 14:06:46 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa3.mentor.iphmx.com (esa3.mentor.iphmx.com [68.232.137.180]) by sourceware.org (Postfix) with ESMTPS id D649D3858C2F; Tue, 16 Aug 2022 14:06:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D649D3858C2F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mentor.com X-IronPort-AV: E=Sophos;i="5.93,241,1654588800"; d="diff'?scan'208";a="81254809" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa3.mentor.iphmx.com with ESMTP; 16 Aug 2022 06:06:12 -0800 IronPort-SDR: v0J9iFLvuKKSeJDXElzIDDcMbsv42dkjjQa29bP+tHFxAfe1mXkBYGshsAiWiJCMv19SFTBCvu rDG8J51vAnpfe13s5MTWe4t9C/rPkHRHYyyqF++0Fq8ogW/Qe1RljJf2EqZrOWNfhu8EPW8kGO kGZ9Z0iq1eXWyED1f3BMsxi4YRyTZbHcijJORIzrpfk+IVoCOd2bSPQuTG7MsQBvrfZoFyZela c5pnQInqfGrXgwEJguQ5O1mI4IJgJjM49V3Iy6v5ylY1HNkXcwsNuW8iZptFIMZwlhzNxjDWGk yvg= Message-ID: <9dde1b4a-03cb-214c-8eb7-8f75978754c7@codesourcery.com> Date: Tue, 16 Aug 2022 16:06:05 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.12.0 Content-Language: en-US To: gcc-patches , fortran , Jakub Jelinek From: Tobias Burnus Subject: [Patch] Fortran: OpenMP fix declare simd inside modules and absent linear [PR106566] X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) To svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1741326985392645734?= X-GMAIL-MSGID: =?utf-8?q?1741326985392645734?= This patch fixes two issues – the first was reported to me by email but it also shows up in the official OpenMP examples (see PR). Namely: Inside a module, 'gfc_match(" ( %s )")' fails as the symbol is already host associated. (The symbol is the current procedure name.) Solution: Match with passing (permit) host_assoc = true to the match function instead of 'false' as done with '%s'. Afterwards, it was failing when folding a NULL_TREE. Solution: Init the linear step with 1 in that case. OK for mainline? * * * I have not checked GCC < mainline. The current example is OpenMP 5.2 only and only supported since June 7, 2022 in C/C++ and July 4 for Fortran. However, I assume the same issue also affects GCC < 13 with a tailored testcase. - If there is the sentiment to fix it also for older GCC, I can come up with modified testcases and a GCC 12 (and GCC 11?) patch. Thoughts? Tobias ----------------- Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955 Fortran: OpenMP fix declare simd inside modules and absent linear [PR106566] gcc/fortran/ChangeLog: PR fortran/106566 * openmp.cc (gfc_match_omp_declare_simd): Accept module procedures. * trans-openmp.cc (gfc_trans_omp_clauses): Fix declare simd without linear-step value. gcc/testsuite/ChangeLog: PR fortran/106566 * gfortran.dg/gomp/declare-simd-4.f90: New test. * gfortran.dg/gomp/declare-simd-5.f90: New test. gcc/fortran/openmp.cc | 8 +++- gcc/fortran/trans-openmp.cc | 2 + gcc/testsuite/gfortran.dg/gomp/declare-simd-4.f90 | 42 +++++++++++++++++++ gcc/testsuite/gfortran.dg/gomp/declare-simd-5.f90 | 49 +++++++++++++++++++++++ 4 files changed, 99 insertions(+), 2 deletions(-) diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc index a7eb6c3e8f4..e430f4c49dd 100644 --- a/gcc/fortran/openmp.cc +++ b/gcc/fortran/openmp.cc @@ -4213,9 +4213,13 @@ gfc_match_omp_declare_simd (void) gfc_omp_declare_simd *ods; bool needs_space = false; - switch (gfc_match (" ( %s ) ", &proc_name)) + switch (gfc_match (" ( ")) { - case MATCH_YES: break; + case MATCH_YES: + if (gfc_match_symbol (&proc_name, /* host assoc = */ true) != MATCH_YES + || gfc_match (" ) ") != MATCH_YES) + return MATCH_ERROR; + break; case MATCH_NO: proc_name = NULL; needs_space = true; break; case MATCH_ERROR: return MATCH_ERROR; } diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc index de27ed52c02..22e6dd254c7 100644 --- a/gcc/fortran/trans-openmp.cc +++ b/gcc/fortran/trans-openmp.cc @@ -2798,6 +2798,8 @@ gfc_trans_omp_clauses (stmtblock_t *block, gfc_omp_clauses *clauses, } else { + if (last_step == NULL_TREE) + last_step = size_one_node; if (kind == OMP_CLAUSE_LINEAR_REF) { tree type; diff --git a/gcc/testsuite/gfortran.dg/gomp/declare-simd-4.f90 b/gcc/testsuite/gfortran.dg/gomp/declare-simd-4.f90 new file mode 100644 index 00000000000..44132525963 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/declare-simd-4.f90 @@ -0,0 +1,42 @@ +! { dg-do compile } +! { dg-additional-options "-fdump-tree-gimple" } +! +! PR fortran/106566 +! +! { dg-final { scan-tree-dump-times "__attribute__\\(\\(omp declare simd \\(linear\\(0:ref,step\\(4\\)\\) simdlen\\(8\\)\\)\\)\\)" 2 "gimple" } } +! { dg-final { scan-tree-dump-times "__attribute__\\(\\(omp declare simd \\(linear\\(0:ref,step\\(8\\)\\) simdlen\\(8\\)\\)\\)\\)" 2 "gimple" } } + +subroutine add_one2(p) + implicit none + !$omp declare simd(add_one2) linear(p: ref) simdlen(8) + integer :: p + + p = p + 1 +end subroutine + +subroutine linear_add_one2(p) + implicit none + !$omp declare simd(linear_add_one2) linear(p: ref, step(2)) simdlen(8) + integer :: p + + p = p + 1 +end subroutine + +module m + integer, parameter :: NN = 1023 + integer :: a(NN) +contains + subroutine module_add_one2(q) + implicit none + !$omp declare simd(module_add_one2) linear(q: ref) simdlen(8) + integer :: q + q = q + 1 + end subroutine + + subroutine linear_add_one2(q) + implicit none + !$omp declare simd(linear_add_one2) linear(q: ref, step(2)) simdlen(8) + integer :: q + q = q + 1 + end subroutine +end module diff --git a/gcc/testsuite/gfortran.dg/gomp/declare-simd-5.f90 b/gcc/testsuite/gfortran.dg/gomp/declare-simd-5.f90 new file mode 100644 index 00000000000..f5880f50090 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/declare-simd-5.f90 @@ -0,0 +1,49 @@ +! { dg-do compile } +! +! PR fortran/106566 +! + +subroutine add_one2(p) + implicit none + procedure(add_one2) :: ext1 + !$omp declare simd(ext1) linear(p: ref) simdlen(8) ! { dg-error "OMP DECLARE SIMD should refer to containing procedure 'add_one2'" } + integer :: p + + p = p + 1 +end subroutine + +subroutine linear_add_one2(p) + implicit none + procedure(linear_add_one2) :: ext2 + !$omp declare simd(ext2) linear(p: ref, step(2)) simdlen(8) ! { dg-error "OMP DECLARE SIMD should refer to containing procedure 'linear_add_one2'" } + integer :: p + + p = p + 1 +end subroutine + +module m + integer, parameter :: NN = 1023 + integer :: a(NN) +contains + subroutine some_proc(r) + integer :: r + end subroutine + subroutine module_add_one2(q) + implicit none + !$omp declare simd(some_proc) linear(q: ref) simdlen(8) ! { dg-error "OMP DECLARE SIMD should refer to containing procedure 'module_add_one2'" } + integer :: q + q = q + 1 + end subroutine + + subroutine module_linear_add_one2(q) + implicit none + interface + subroutine other_proc(r) + integer :: r + end subroutine + end interface + !$omp declare simd(other_proc) linear(q: ref, step(2)) simdlen(8) ! { dg-error "OMP DECLARE SIMD should refer to containing procedure 'module_linear_add_one2'" } + integer :: q + q = q + 1 + end subroutine +end module