From patchwork Thu Oct 6 10:55:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Tobias Burnus X-Patchwork-Id: 1780 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp247155wrs; Thu, 6 Oct 2022 03:55:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6tzGyjVtf8MZgcLPvIBXAbwgJhsRvSTF1opJdGCm6jjuL6mlLlj3wQ51kWeVgV6fGzvLmK X-Received: by 2002:a17:907:9493:b0:78d:765:6cc9 with SMTP id dm19-20020a170907949300b0078d07656cc9mr3525459ejc.265.1665053759438; Thu, 06 Oct 2022 03:55:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665053759; cv=none; d=google.com; s=arc-20160816; b=Hx6wwOwvoiPitCUXIO30pWFhGA1G/wlsr5vHDfsPpWIhh+QKmZ0nbLwGwTZ5X0JMfC nPjC5LDkHswwIMRGemU5/Xhve/Yi8BcarBbq5ol6PuUrokP9baWVdhyqiCvg85Dar0LI XYT8rXDtTChIL9qZbGmf2/9jdxQ3exJUVmPZo2BUECNzDPUx3oHHFHTmGzXGJdhq3oVI xYfrWInv+G29UdnkqcwFzkGYMMKj64dPJlROnBoDp+Mh7zYzTdgGrLYLkXW84bnA2oS+ Rixb6WNxDkaRwqkO47dp8wM0mq8H7N03y/FkuZWZdMWbgVGgPUDAx/6NosR3axy7+uGR UCwA== 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=l6CHu8hgZZngfJHiiVivt6zgO7xqlGFG5WCrL1229Sk=; b=A6Sr8xEegx5Afq0R5omDp35fTkKg8dLLv0kmC+1Yb8g6A9wLTxcPm4+whJp3aJhR+I 3kzDg9iPWC2C+lQr6yh24a3k0quuovejDR70I5VM4hAZi7JLxo5TsXnlDyaqjGW7oD9i XrrAIKp4ClElFI1sLtyMwdyafmyD6FshEWKb3B2ukLjQ/FNTX/ByZQYuS3QxirIZz8aX 2qZ7EhCDVo9McBfczzYsB/J6vMotJo+fQpvmsdQLn1rb9BKDbKTMabAyKruvAnwItY1D p/wDW06IkkBGXYHKev31hI7fEVjfa3oUxNY4ThPCYoNj0g3wUTTMUu5tdkHYZx0//3l2 q3jA== 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 i7-20020a50fc07000000b00454b9403108si853402edr.219.2022.10.06.03.55.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 03:55:59 -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 B60C73821FC3 for ; Thu, 6 Oct 2022 10:55:34 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from esa1.mentor.iphmx.com (esa1.mentor.iphmx.com [68.232.129.153]) by sourceware.org (Postfix) with ESMTPS id 60732383FB86; Thu, 6 Oct 2022 10:55:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 60732383FB86 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.95,163,1661846400"; d="diff'?scan'208";a="87009033" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 06 Oct 2022 02:55:06 -0800 IronPort-SDR: +OxlVNBpL2La5cdN1YKDZpx/zzyoNdAyaNJKBD+HHo7ytceEJ/hmVUnQvynIPwhxdkWIYR4HAI A5GyDK5zJbgFUUhsXrtmN2lZh8H0Xi7/iJmnWGI/XaVptD9bBce6aHxuDFLZWeltXxCC88vpe/ dbMT2k8DvCi/lM46JpOCKgS29LhgSEgC94j7h1pD3KqsZSVVvdDp7fADKAfCqqhr3Lcdhw5l+2 TaMa1b3+GZHN+AAANHx+SHMNckDTkFYZ/QLpWmJC2UpCa/S9r39Loy85Z0vrxjJpPKuODjTpPL HL8= Message-ID: Date: Thu, 6 Oct 2022 12:55:01 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.3.1 Content-Language: en-US To: gcc-patches , fortran , Jakub Jelinek From: Tobias Burnus Subject: [Patch] openmp: Map holds clause to IFN_ASSUME for Fortran X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) 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 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?1745935410637816293?= X-GMAIL-MSGID: =?utf-8?q?1745935410637816293?= Same as for C/C++, albeit a tiny bit longer patch. I don't know whether it makes sense to handle – in the long run – the case of se.pre/se.post being nonempty – and, if so, how. OK for mainline? 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 openmp: Map holds clause to IFN_ASSUME for Fortran Same as r13-3107-g847f5addc4d07a2f3b95f5daa50ab4a64dfd957d did for C/C++. Convert '!$omp assume holds(cond)' to IFN_ASSUME (cond). gcc/fortran/ * trans-openmp.cc (gfc_trans_omp_assume): New. (gfc_trans_omp_directive): Call it. gcc/teststuite/ * gfortran.dg/gomp/assume-3.f90: New test. gcc/fortran/trans-openmp.cc | 27 ++++++++++++++++- gcc/testsuite/gfortran.dg/gomp/assume-3.f90 | 46 +++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 1 deletion(-) diff --git a/gcc/fortran/trans-openmp.cc b/gcc/fortran/trans-openmp.cc index 21053694f81..b82257258a7 100644 --- a/gcc/fortran/trans-openmp.cc +++ b/gcc/fortran/trans-openmp.cc @@ -4570,6 +4570,31 @@ gfc_trans_oacc_wait_directive (gfc_code *code) static tree gfc_trans_omp_sections (gfc_code *, gfc_omp_clauses *); static tree gfc_trans_omp_workshare (gfc_code *, gfc_omp_clauses *); +static tree +gfc_trans_omp_assume (gfc_code *code) +{ + stmtblock_t block; + gfc_init_block (&block); + gfc_omp_assumptions *assume = code->ext.omp_clauses->assume; + if (assume) + for (gfc_expr_list *el = assume->holds; el; el = el->next) + { + tree t; + gfc_se se; + gfc_init_se (&se, NULL); + gfc_conv_expr (&se, el->expr); + /* Avoid side effects. */ + if (se.pre.head || se.post.head) + continue; + t = build_call_expr_internal_loc (gfc_get_location (&el->expr->where), + IFN_ASSUME, void_type_node, 1, + se.expr); + gfc_add_expr_to_block (&block, t); + } + gfc_add_expr_to_block (&block, gfc_trans_omp_code (code->block->next, true)); + return gfc_finish_block (&block); +} + static tree gfc_trans_omp_atomic (gfc_code *code) { @@ -7488,7 +7513,7 @@ gfc_trans_omp_directive (gfc_code *code) switch (code->op) { case EXEC_OMP_ASSUME: - return gfc_trans_omp_code (code->block->next, true); + return gfc_trans_omp_assume (code); case EXEC_OMP_ATOMIC: return gfc_trans_omp_atomic (code); case EXEC_OMP_BARRIER: diff --git a/gcc/testsuite/gfortran.dg/gomp/assume-3.f90 b/gcc/testsuite/gfortran.dg/gomp/assume-3.f90 new file mode 100644 index 00000000000..e5deace306e --- /dev/null +++ b/gcc/testsuite/gfortran.dg/gomp/assume-3.f90 @@ -0,0 +1,46 @@ +! { dg-do compile } +! { dg-options "-fopenmp -O2 -fdump-tree-optimized -fdump-tree-original" } + +! { dg-final { scan-tree-dump-times ".ASSUME \\(x == 42\\);" 1 "original" } } +! { dg-final { scan-tree-dump-times ".ASSUME \\(x <= 41\\);" 1 "original" } } +! { dg-final { scan-tree-dump-times ".ASSUME \\(y <= 6\\);" 1 "original" } } +! { dg-final { scan-tree-dump-times ".ASSUME \\(y > 5\\);" 1 "original" } } + +! { dg-final { scan-tree-dump-times "return 42;" 3 "optimized" } } +! { dg-final { scan-tree-dump-not "return -1;" "optimized" } } + +integer function foo (x) + implicit none + integer, value :: x + integer :: y + !$omp assume holds (x == 42) + y = x; + !$omp end assume + foo = y +end + +integer function bar (x) + implicit none + integer, value :: x + !$omp assume holds (x < 42) + block + end block + if (x == 42) then + bar = -1 + return + end if + bar = 42 +end + +integer function foobar (y) + implicit none + integer, value :: y + !$omp assume holds(y > 5) holds (y < 7) + block + if (y == 6) then + foobar = 42 + return + end if + end block + foobar = -1 +end