From patchwork Fri Jul 28 13:04:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frederik Harwath X-Patchwork-Id: 1814272 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from server2.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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RC7Cb1f4Sz1ybX for ; Fri, 28 Jul 2023 23:05:15 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2FA4D385DC26 for ; Fri, 28 Jul 2023 13:05:13 +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 274253858CDA for ; Fri, 28 Jul 2023 13:04:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 274253858CDA 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="6.01,237,1684828800"; d="scan'208";a="14532013" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 28 Jul 2023 05:04:52 -0800 IronPort-SDR: e2Hp337Bwa53C7ILUF1aT/NK2HZvR3u/hadBrYqZAB0Kc8xds1xcltPNbvlOgeLnlQzdGXjWnv BKhJXmra5XzPR+p0TxGmj2aHTLsA+4LQIukmwXA3uqQIv3twrDDjrnc6Gw+cNHky2qN9TbKTG8 PJP45XGt7x2/t7E1Wj7sw/aIff89HWyHduUiSBznEwA3swEeQ01Mg3h9IaMZZX3CFbc8Qwe5Yd e13lHsAT4ylPcmUb07+ZO27aMCp94KH6q9M8iJwhfvABfsjnCbx2vwtOKvMXK3oLvH6mpX4kVk IaY= From: Frederik Harwath To: , , Subject: [PATCH 1/4] openmp: Fix loop transformation tests Date: Fri, 28 Jul 2023 13:04:30 +0000 Message-ID: <20230728130433.2377366-2-frederik@codesourcery.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230728130433.2377366-1-frederik@codesourcery.com> References: <20230324153046.3996092-1-frederik@codesourcery.com> <20230728130433.2377366-1-frederik@codesourcery.com> MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-12.5 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" libgomp/ChangeLog: * testsuite/libgomp.fortran/loop-transforms/tile-2.f90: Add reduction clause. * testsuite/libgomp.fortran/loop-transforms/unroll-1.f90: Initialize var. * testsuite/libgomp.fortran/loop-transforms/unroll-simd-1.f90: Add reduction and initialization. --- libgomp/testsuite/libgomp.fortran/loop-transforms/tile-2.f90 | 2 +- libgomp/testsuite/libgomp.fortran/loop-transforms/unroll-1.f90 | 2 ++ .../libgomp.fortran/loop-transforms/unroll-simd-1.f90 | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) -- 2.36.1 ----------------- 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 diff --git a/libgomp/testsuite/libgomp.fortran/loop-transforms/tile-2.f90 b/libgomp/testsuite/libgomp.fortran/loop-transforms/tile-2.f90 index 6aedbf4724f..a7cb5e7635d 100644 --- a/libgomp/testsuite/libgomp.fortran/loop-transforms/tile-2.f90 +++ b/libgomp/testsuite/libgomp.fortran/loop-transforms/tile-2.f90 @@ -69,7 +69,7 @@ module test_functions integer :: i,j sum = 0 - !$omp parallel do collapse(2) + !$omp parallel do collapse(2) reduction(+:sum) !$omp tile sizes(6,10) do i = 1,10,3 do j = 1,10,3 diff --git a/libgomp/testsuite/libgomp.fortran/loop-transforms/unroll-1.f90 b/libgomp/testsuite/libgomp.fortran/loop-transforms/unroll-1.f90 index f07aab898fa..b91ea275577 100644 --- a/libgomp/testsuite/libgomp.fortran/loop-transforms/unroll-1.f90 +++ b/libgomp/testsuite/libgomp.fortran/loop-transforms/unroll-1.f90 @@ -8,6 +8,7 @@ module test_functions integer :: i,j + sum = 0 !$omp do do i = 1,10,3 !$omp unroll full @@ -22,6 +23,7 @@ module test_functions integer :: i,j + sum = 0 !$omp parallel do reduction(+:sum) !$omp unroll partial(2) do i = 1,10,3 diff --git a/libgomp/testsuite/libgomp.fortran/loop-transforms/unroll-simd-1.f90 b/libgomp/testsuite/libgomp.fortran/loop-transforms/unroll-simd-1.f90 index 5fb64ddd6fd..7a43458f0dd 100644 --- a/libgomp/testsuite/libgomp.fortran/loop-transforms/unroll-simd-1.f90 +++ b/libgomp/testsuite/libgomp.fortran/loop-transforms/unroll-simd-1.f90 @@ -9,7 +9,8 @@ module test_functions integer :: i,j - !$omp simd + sum = 0 + !$omp simd reduction(+:sum) do i = 1,10,3 !$omp unroll full do j = 1,10,3 From patchwork Fri Jul 28 13:04:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frederik Harwath X-Patchwork-Id: 1814276 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from server2.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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RC7DH55LLz1ydx for ; Fri, 28 Jul 2023 23:05:51 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 80F973853559 for ; Fri, 28 Jul 2023 13:05:45 +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 E84263858C27 for ; Fri, 28 Jul 2023 13:04:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E84263858C27 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="6.01,237,1684828800"; d="scan'208";a="14532016" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 28 Jul 2023 05:04:54 -0800 IronPort-SDR: bESWMvMn4bJWcXSAYn88iXrdBdOwqZyKAJ5m+dRkyo1szKsp8xD9wXkkqJtdGevIo4hL0xjqkX +aP6vzzEPBApxjc9u8tG3cTRiVDINyKlvw30jRJxP0T/P13w8fSQZawGhiKaudnHtOGwn94qJt hERuhbXUGvWqpGJhPYjX69ERyiJegr/INkpk5K0ChjuVqmp7vzXszBHR+v6zXyOLfIqCaJagiA L9YUN452m1xzgBMwBA3V0Ieq/cFkwnROMNt7IADGFf8Ie3eMsUcxNc6nRWQGqg8ic+r01ec6G7 s8U= From: Frederik Harwath To: , , Subject: [PATCH 2/4] openmp: Fix initialization for 'unroll full' Date: Fri, 28 Jul 2023 13:04:31 +0000 Message-ID: <20230728130433.2377366-3-frederik@codesourcery.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230728130433.2377366-1-frederik@codesourcery.com> References: <20230324153046.3996092-1-frederik@codesourcery.com> <20230728130433.2377366-1-frederik@codesourcery.com> MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-12.5 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The index variable initialization for the 'omp unroll' directive with 'full' clause got lost and the testsuite did not catch it. Add the initialization and add -Wall to some tests to detect uninitialized variable uses and other potential problems in the code generation. gcc/ChangeLog: * omp-transform-loops.cc (full_unroll): Add initialization of index variable. libgomp/ChangeLog: * testsuite/libgomp.c-c++-common/loop-transforms/matrix-no-directive-unroll-full-1.c: Use -Wall and add -Wno-unknown-pragmas to disable warnings about empty pragmas. Use -O2. * testsuite/libgomp.c++/loop-transforms/matrix-no-directive-unroll-full-1.C: Copy of testsuite/libgomp.c-c++-common/matrix-no-directive-unroll-full-1.c, but using -O0 which works only for C++. * testsuite/libgomp.c-c++-common/loop-transforms/matrix-no-directive-1.c: Use -Wall and use -Wno-unknown-pragmas to disable warnings about empty pragmas. * testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-distribute-parallel-for-1.c: Likewise. * testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-for-1.c: Likewise. * testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-parallel-for-1.c: Likewise. * testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-parallel-masked-taskloop-1.c: Likewise. * testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-parallel-masked-taskloop-simd-1.c: Likewise. * testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-target-parallel-for-1.c: Likewise. * testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-target-teams-distribute-parallel-for-1.c: Likewise. * testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-taskloop-1.c: Likewise. * testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-teams-distribute-parallel-for-1.c: Likewise. * testsuite/libgomp.c-c++-common/loop-transforms/matrix-simd-1.c: Likewise. * testsuite/libgomp.c-c++-common/loop-transforms/unroll-non-rect-1.c: Likewise. * testsuite/libgomp.c-c++-common/loop-transforms/unroll-1.c: Likewise and fix broken function calls found by -Wall. --- gcc/omp-transform-loops.cc | 1 + .../matrix-no-directive-unroll-full-1.C | 13 +++++++++++++ .../loop-transforms/matrix-no-directive-1.c | 2 +- .../matrix-no-directive-unroll-full-1.c | 2 +- .../matrix-omp-distribute-parallel-for-1.c | 2 ++ .../loop-transforms/matrix-omp-for-1.c | 2 +- .../loop-transforms/matrix-omp-parallel-for-1.c | 2 +- .../matrix-omp-parallel-masked-taskloop-1.c | 2 ++ .../matrix-omp-parallel-masked-taskloop-simd-1.c | 2 ++ .../matrix-omp-target-parallel-for-1.c | 2 +- ...rix-omp-target-teams-distribute-parallel-for-1.c | 2 ++ .../loop-transforms/matrix-omp-taskloop-1.c | 2 ++ .../matrix-omp-teams-distribute-parallel-for-1.c | 2 ++ .../loop-transforms/matrix-simd-1.c | 2 ++ .../libgomp.c-c++-common/loop-transforms/unroll-1.c | 8 +++++--- .../loop-transforms/unroll-non-rect-1.c | 2 ++ 16 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 libgomp/testsuite/libgomp.c++/loop-transforms/matrix-no-directive-unroll-full-1.C -- 2.36.1 ----------------- 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 diff --git a/gcc/omp-transform-loops.cc b/gcc/omp-transform-loops.cc index 517faea537c..275a5260dae 100644 --- a/gcc/omp-transform-loops.cc +++ b/gcc/omp-transform-loops.cc @@ -548,6 +548,7 @@ full_unroll (gomp_for *omp_for, location_t loc, walk_ctx *ctx ATTRIBUTE_UNUSED) gimple_seq unrolled = NULL; gimple_seq_add_seq (&unrolled, gimple_omp_for_pre_body (omp_for)); + gimplify_assign (index, init, &unrolled); push_gimplify_context (); gimple_seq_add_seq (&unrolled, build_unroll_body (body, unroll_factor, index, incr)); diff --git a/libgomp/testsuite/libgomp.c++/loop-transforms/matrix-no-directive-unroll-full-1.C b/libgomp/testsuite/libgomp.c++/loop-transforms/matrix-no-directive-unroll-full-1.C new file mode 100644 index 00000000000..3a684219627 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/loop-transforms/matrix-no-directive-unroll-full-1.C @@ -0,0 +1,13 @@ +/* { dg-additional-options { -O0 -fdump-tree-original -Wall -Wno-unknown-pragmas } } */ + +#define COMMON_DIRECTIVE +#define COMMON_TOP_TRANSFORM omp unroll full +#define COLLAPSE_1 +#define COLLAPSE_2 +#define COLLAPSE_3 +#define IMPLEMENTATION_FILE "../../libgomp.c-c++-common/loop-transforms/matrix-constant-iter.h" + +#include "../../libgomp.c-c++-common/loop-transforms/matrix-transform-variants-1.h" + +/* A consistency check to prevent broken macro usage. */ +/* { dg-final { scan-tree-dump-times "unroll_full" 13 "original" } } */ diff --git a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-no-directive-1.c b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-no-directive-1.c index 9f7f02041b0..7904a5617f3 100644 --- a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-no-directive-1.c +++ b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-no-directive-1.c @@ -1,4 +1,4 @@ -/* { dg-additional-options {-fdump-tree-original} } */ +/* { dg-additional-options { -fdump-tree-original -Wall -Wno-unknown-pragmas } } */ #define COMMON_DIRECTIVE #define COLLAPSE_1 collapse(1) diff --git a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-no-directive-unroll-full-1.c b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-no-directive-unroll-full-1.c index 5dd0b5d2989..bd431a25102 100644 --- a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-no-directive-unroll-full-1.c +++ b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-no-directive-unroll-full-1.c @@ -1,4 +1,4 @@ -/* { dg-additional-options {-fdump-tree-original} } */ +/* { dg-additional-options { -O2 -fdump-tree-original -Wall -Wno-unknown-pragmas } } */ #define COMMON_DIRECTIVE #define COMMON_TOP_TRANSFORM omp unroll full diff --git a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-distribute-parallel-for-1.c b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-distribute-parallel-for-1.c index d855857e5ee..3875014dc96 100644 --- a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-distribute-parallel-for-1.c +++ b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-distribute-parallel-for-1.c @@ -1,3 +1,5 @@ +/* { dg-additional-options { -Wall -Wno-unknown-pragmas } } */ + #define COMMON_DIRECTIVE "omp teams distribute parallel for" #define COLLAPSE_1 "collapse(1)" #define COLLAPSE_2 "collapse(2)" diff --git a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-for-1.c b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-for-1.c index f2a2b80b2fd..671396cd533 100644 --- a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-for-1.c +++ b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-for-1.c @@ -1,4 +1,4 @@ -/* { dg-additional-options {-fdump-tree-original} } */ +/* { dg-additional-options { -fdump-tree-original -Wall -Wno-unknown-pragmas } } */ #define COMMON_DIRECTIVE omp for #define COLLAPSE_1 collapse(1) diff --git a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-parallel-for-1.c b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-parallel-for-1.c index 2c5701efca4..cc66df42679 100644 --- a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-parallel-for-1.c +++ b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-parallel-for-1.c @@ -1,4 +1,4 @@ -/* { dg-additional-options {-fdump-tree-original} } */ +/* { dg-additional-options { -fdump-tree-original -Wall -Wno-unknown-pragmas } } */ #define COMMON_DIRECTIVE omp parallel for #define COLLAPSE_1 collapse(1) diff --git a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-parallel-masked-taskloop-1.c b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-parallel-masked-taskloop-1.c index e2def212725..890b460f374 100644 --- a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-parallel-masked-taskloop-1.c +++ b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-parallel-masked-taskloop-1.c @@ -1,3 +1,5 @@ +/* { dg-additional-options { -Wall -Wno-unknown-pragmas } } */ + #define COMMON_DIRECTIVE omp parallel masked taskloop #define COLLAPSE_1 collapse(1) #define COLLAPSE_2 collapse(2) diff --git a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-parallel-masked-taskloop-simd-1.c b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-parallel-masked-taskloop-simd-1.c index ce601555cfb..74f6271504a 100644 --- a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-parallel-masked-taskloop-simd-1.c +++ b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-parallel-masked-taskloop-simd-1.c @@ -1,3 +1,5 @@ +/* { dg-additional-options { -Wall -Wno-unknown-pragmas } } */ + #define COMMON_DIRECTIVE omp parallel masked taskloop simd #define COLLAPSE_1 collapse(1) #define COLLAPSE_2 collapse(2) diff --git a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-target-parallel-for-1.c b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-target-parallel-for-1.c index 365b39ba385..8138ea57f38 100644 --- a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-target-parallel-for-1.c +++ b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-target-parallel-for-1.c @@ -1,4 +1,4 @@ -/* { dg-additional-options {-fdump-tree-original} } */ +/* { dg-additional-options { -fdump-tree-original -Wall -Wno-unknown-pragmas } } */ #define COMMON_DIRECTIVE omp target parallel for map(tofrom:result[0:dim0*dim1]) map(to:matrix1[0:dim0*dim1], matrix2[0:dim0*dim1]) #define COLLAPSE_1 collapse(1) diff --git a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-target-teams-distribute-parallel-for-1.c b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-target-teams-distribute-parallel-for-1.c index 8afe34874c9..d4d162d9c2b 100644 --- a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-target-teams-distribute-parallel-for-1.c +++ b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-target-teams-distribute-parallel-for-1.c @@ -1,3 +1,5 @@ +/* { dg-additional-options { -Wall -Wno-unknown-pragmas } } */ + #define COMMON_DIRECTIVE omp target teams distribute parallel for map(tofrom:result[:dim0*dim1]) map(to:matrix1[0:dim0*dim1], matrix2[0:dim0*dim1]) #define COLLAPSE_1 collapse(1) #define COLLAPSE_2 collapse(2) diff --git a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-taskloop-1.c b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-taskloop-1.c index bbc78b39db0..28edb6ce83e 100644 --- a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-taskloop-1.c +++ b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-taskloop-1.c @@ -1,3 +1,5 @@ +/* { dg-additional-options { -Wall -Wno-unknown-pragmas } } */ + #define COMMON_DIRECTIVE omp taskloop #define COLLAPSE_1 collapse(1) #define COLLAPSE_2 collapse(2) diff --git a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-teams-distribute-parallel-for-1.c b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-teams-distribute-parallel-for-1.c index 3a58e479374..481a20a18d0 100644 --- a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-teams-distribute-parallel-for-1.c +++ b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-omp-teams-distribute-parallel-for-1.c @@ -1,3 +1,5 @@ +/* { dg-additional-options { -Wall -Wno-unknown-pragmas } } */ + #define COMMON_DIRECTIVE omp teams distribute parallel for #define COLLAPSE_1 collapse(1) #define COLLAPSE_2 collapse(2) diff --git a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-simd-1.c b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-simd-1.c index e5155dcf76d..200ddd859f5 100644 --- a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-simd-1.c +++ b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/matrix-simd-1.c @@ -1,3 +1,5 @@ +/* { dg-additional-options { -Wall -Wno-unknown-pragmas } } */ + #define COMMON_DIRECTIVE omp simd #define COLLAPSE_1 collapse(1) #define COLLAPSE_2 collapse(2) diff --git a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/unroll-1.c b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/unroll-1.c index 2ac0fff16af..eb5d3d77eb8 100644 --- a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/unroll-1.c +++ b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/unroll-1.c @@ -1,3 +1,5 @@ +/* { dg-additional-options { -Wall -Wno-unknown-pragmas } } */ + #include int compute_sum1 () @@ -11,7 +13,7 @@ int compute_sum1 () sum++; if (j != 7) - __builtin_abort; + __builtin_abort (); return sum; } @@ -27,7 +29,7 @@ int compute_sum2() sum++; if (j != 7) - __builtin_abort; + __builtin_abort (); return sum; } @@ -43,7 +45,7 @@ int compute_sum3() sum++; if (j != 7) - __builtin_abort; + __builtin_abort (); return sum; } diff --git a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/unroll-non-rect-1.c b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/unroll-non-rect-1.c index 2f9924aea1f..7bd9b906235 100644 --- a/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/unroll-non-rect-1.c +++ b/libgomp/testsuite/libgomp.c-c++-common/loop-transforms/unroll-non-rect-1.c @@ -1,3 +1,5 @@ +/* { dg-additional-options { -Wall -Wno-unknown-pragmas } } */ + #include #include From patchwork Fri Jul 28 13:04:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frederik Harwath X-Patchwork-Id: 1814275 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RC7DG6yqYz1ybX for ; Fri, 28 Jul 2023 23:05:50 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 871B1383E8F6 for ; Fri, 28 Jul 2023 13:05:44 +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 B1D87385841B for ; Fri, 28 Jul 2023 13:05:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B1D87385841B 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="6.01,237,1684828800"; d="scan'208";a="14532019" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 28 Jul 2023 05:04:56 -0800 IronPort-SDR: P8ruQTQeHgcTam0EndK/PhnJVgwD/Mr8qJLkLDd7MGFoNngKPn5b5u44oH/upNCbbzv/iYIzr6 0LvjdNnxtRM+5BmThRyF7+YwkJQX+LSP1f0rm11oK15Z8xwIm4UT7bbHUxh8kHImLIOIb4IKqD 04hSVZlJ4DLLIdyVEshMO+4/vFLHPfaYnipI5YlG+F7JMCqZcoUKah+KduXIG+fNS7Ws5NFUgO tmOu/O2zO3CovnpVO21d39SnRD21k2bqinAYFNKFgM//Q29unT4/dLLFYtrBG5M20FkRXKjJZk Ypc= From: Frederik Harwath To: , , Subject: [PATCH 3/4] openmp: Fix diagnostic message for "omp unroll" Date: Fri, 28 Jul 2023 13:04:32 +0000 Message-ID: <20230728130433.2377366-4-frederik@codesourcery.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230728130433.2377366-1-frederik@codesourcery.com> References: <20230324153046.3996092-1-frederik@codesourcery.com> <20230728130433.2377366-1-frederik@codesourcery.com> MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-12.5 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" gcc/ChangeLog: * omp-transform-loops.cc (print_optimized_unroll_partial_msg): Output "omp unroll partial" instead of "omp unroll auto". (optimize_transformation_clauses): Likewise. libgomp/ChangeLog: * testsuite/libgomp.fortran/loop-transforms/unroll-6.f90: Adjust. gcc/testsuite/ChangeLog: * gfortran.dg/gomp/loop-transforms/unroll-8.f90: Adjust. * gfortran.dg/gomp/loop-transforms/unroll-9.f90: Adjust. --- gcc/omp-transform-loops.cc | 4 ++-- gcc/testsuite/gfortran.dg/gomp/loop-transforms/unroll-8.f90 | 2 +- gcc/testsuite/gfortran.dg/gomp/loop-transforms/unroll-9.f90 | 2 +- .../testsuite/libgomp.fortran/loop-transforms/unroll-6.f90 | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) -- 2.36.1 ----------------- 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 diff --git a/gcc/omp-transform-loops.cc b/gcc/omp-transform-loops.cc index 275a5260dae..c8853bcee89 100644 --- a/gcc/omp-transform-loops.cc +++ b/gcc/omp-transform-loops.cc @@ -1423,7 +1423,7 @@ print_optimized_unroll_partial_msg (tree c) tree unroll_factor = OMP_CLAUSE_UNROLL_PARTIAL_EXPR (c); dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, dump_loc, "replaced consecutive % directives by " - "%\n", tree_to_uhwi (unroll_factor)); } @@ -1483,7 +1483,7 @@ optimize_transformation_clauses (tree clauses) dump_printf_loc ( MSG_OPTIMIZED_LOCATIONS, dump_loc, - "removed useless % directives " + "removed useless % directives " "preceding 'omp unroll full'\n"); } } diff --git a/gcc/testsuite/gfortran.dg/gomp/loop-transforms/unroll-8.f90 b/gcc/testsuite/gfortran.dg/gomp/loop-transforms/unroll-8.f90 index fd687890ee6..dab3f0fb5cf 100644 --- a/gcc/testsuite/gfortran.dg/gomp/loop-transforms/unroll-8.f90 +++ b/gcc/testsuite/gfortran.dg/gomp/loop-transforms/unroll-8.f90 @@ -5,7 +5,7 @@ subroutine test1 implicit none integer :: i !$omp parallel do collapse(1) - !$omp unroll partial(4) ! { dg-optimized {replaced consecutive 'omp unroll' directives by 'omp unroll auto\(24\)'} } + !$omp unroll partial(4) ! { dg-optimized {replaced consecutive 'omp unroll' directives by 'omp unroll partial\(24\)'} } !$omp unroll partial(3) !$omp unroll partial(2) !$omp unroll partial(1) diff --git a/gcc/testsuite/gfortran.dg/gomp/loop-transforms/unroll-9.f90 b/gcc/testsuite/gfortran.dg/gomp/loop-transforms/unroll-9.f90 index 928ca44e811..91e13ff1b37 100644 --- a/gcc/testsuite/gfortran.dg/gomp/loop-transforms/unroll-9.f90 +++ b/gcc/testsuite/gfortran.dg/gomp/loop-transforms/unroll-9.f90 @@ -4,7 +4,7 @@ subroutine test1 implicit none integer :: i - !$omp unroll full ! { dg-optimized {removed useless 'omp unroll auto' directives preceding 'omp unroll full'} } + !$omp unroll full ! { dg-optimized {removed useless 'omp unroll partial' directives preceding 'omp unroll full'} } !$omp unroll partial(3) !$omp unroll partial(2) !$omp unroll partial(1) diff --git a/libgomp/testsuite/libgomp.fortran/loop-transforms/unroll-6.f90 b/libgomp/testsuite/libgomp.fortran/loop-transforms/unroll-6.f90 index 1df8ce8d5bb..b953ce31b5b 100644 --- a/libgomp/testsuite/libgomp.fortran/loop-transforms/unroll-6.f90 +++ b/libgomp/testsuite/libgomp.fortran/loop-transforms/unroll-6.f90 @@ -22,7 +22,7 @@ contains sum = 0 !$omp parallel do reduction(+:sum) lastprivate(i) - !$omp unroll partial(5) ! { dg-optimized {replaced consecutive 'omp unroll' directives by 'omp unroll auto\(50\)'} } + !$omp unroll partial(5) ! { dg-optimized {replaced consecutive 'omp unroll' directives by 'omp unroll partial\(50\)'} } !$omp unroll partial(10) do i = 1,n,step sum = sum + 1 @@ -36,7 +36,7 @@ contains sum = 0 !$omp parallel do reduction(+:sum) lastprivate(i) do i = 1,n,step - !$omp unroll full ! { dg-optimized {removed useless 'omp unroll auto' directives preceding 'omp unroll full'} } + !$omp unroll full ! { dg-optimized {removed useless 'omp unroll partial' directives preceding 'omp unroll full'} } !$omp unroll partial(10) do j = 1, 1000 sum = sum + 1 From patchwork Fri Jul 28 13:04:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Frederik Harwath X-Patchwork-Id: 1814274 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from server2.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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RC7Ck2sdZz1ybX for ; Fri, 28 Jul 2023 23:05:22 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6F247385AFBD for ; Fri, 28 Jul 2023 13:05:20 +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 B2C0C3858423 for ; Fri, 28 Jul 2023 13:05:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B2C0C3858423 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="6.01,237,1684828800"; d="scan'208";a="14532024" Received: from orw-gwy-02-in.mentorg.com ([192.94.38.167]) by esa2.mentor.iphmx.com with ESMTP; 28 Jul 2023 05:05:00 -0800 IronPort-SDR: pKxvM/fQWCMJYgtW0mUMitzWhBn2m6zU8lPsX/SY1e/taaBXtMzzjiTs2BCQCqCMIKxS1Avghz qQ3PCTSwBCGlMxi6+NO27cyjnWR/bwna7iOdms5sQc5kC8HWNe2xAUR5g7nLpUYwy/dYoA6A99 oSQKQ0mWpP+9tQLp77ZBKqcKeI1kKtJqbMEeprwzYqWXdnhsEWnFZAcK34Yr4Iw1ZXSFb7bx6g F/L+pDGHT5Sdh/5M5p0At7TzvX3HW045ua5omJExIXz0zlL6q7D5gafafrFezmfqg5NoUoM7bV Kso= From: Frederik Harwath To: , , Subject: [PATCH 4/4] openmp: Fix number of iterations computation for "omp unroll full" Date: Fri, 28 Jul 2023 13:04:33 +0000 Message-ID: <20230728130433.2377366-5-frederik@codesourcery.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230728130433.2377366-1-frederik@codesourcery.com> References: <20230324153046.3996092-1-frederik@codesourcery.com> <20230728130433.2377366-1-frederik@codesourcery.com> MIME-Version: 1.0 X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-12.mgc.mentorg.com (139.181.222.12) To svr-ies-mbx-10.mgc.mentorg.com (139.181.222.10) X-Spam-Status: No, score=-12.5 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" gcc/ChangeLog: * omp-transform-loops.cc (gomp_for_number_of_iterations): Always compute "final - init" and do not take absolute value. Identify non-iterating and infinite loops for constant init, final, step values for better diagnostic messages, consistent behaviour in those corner cases, and better testability. (gomp_for_constant_iterations_p): Add new argument to pass on information about infinite loops, and ... (full_unroll): ... use from here to emit a warning and remove unrolled, known infinite loops consistently. (process_omp_for): Only print dump message if loop has not been removed by transformation. gcc/testsuite/ChangeLog: * c-c++-common/gomp/loop-transforms/unroll-8.c: New test. --- gcc/omp-transform-loops.cc | 94 ++++++++++++++----- .../gomp/loop-transforms/unroll-8.c | 76 +++++++++++++++ 2 files changed, 146 insertions(+), 24 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/gomp/loop-transforms/unroll-8.c -- 2.36.1 ----------------- 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 diff --git a/gcc/omp-transform-loops.cc b/gcc/omp-transform-loops.cc index c8853bcee89..b0645397641 100644 --- a/gcc/omp-transform-loops.cc +++ b/gcc/omp-transform-loops.cc @@ -153,20 +153,27 @@ subst_defs (tree expr, gimple_seq seq) return expr; } -/* Return an expression for the number of iterations of the outermost loop of - OMP_FOR. */ +/* Return an expression for the number of iterations of the loop at + the given LEVEL of OMP_FOR. + + If the expression is a negative constant, this means that the loop + is infinite. This can only be recognized for loops with constant + initial, final, and step values. In general, according to the + OpenMP specification, the behaviour is unspecified if the number of + iterations does not fit the types used for their computation, and + hence in particular if the loop is infinite. */ tree gomp_for_number_of_iterations (const gomp_for *omp_for, size_t level) { gcc_assert (!non_rectangular_p (omp_for)); - tree init = gimple_omp_for_initial (omp_for, level); tree final = gimple_omp_for_final (omp_for, level); tree_code cond = gimple_omp_for_cond (omp_for, level); tree index = gimple_omp_for_index (omp_for, level); tree type = gomp_for_iter_count_type (index, final); - tree step = TREE_OPERAND (gimple_omp_for_incr (omp_for, level), 1); + tree incr = gimple_omp_for_incr (omp_for, level); + tree step = omp_get_for_step_from_incr (gimple_location (omp_for), incr); init = subst_defs (init, gimple_omp_for_pre_body (omp_for)); init = fold (init); @@ -181,34 +188,64 @@ gomp_for_number_of_iterations (const gomp_for *omp_for, size_t level) diff_type = ptrdiff_type_node; } - tree diff; - if (cond == GT_EXPR) - diff = fold_build2 (minus_code, diff_type, init, final); - else if (cond == LT_EXPR) - diff = fold_build2 (minus_code, diff_type, final, init); - else - gcc_unreachable (); - diff = fold_build2 (CEIL_DIV_EXPR, type, diff, step); - diff = fold_build1 (ABS_EXPR, type, diff); + /* Identify a simple case in which the loop does not iterate. The + computation below could not tell this apart from an infinite + loop, hence we handle this separately for better diagnostic + messages. */ + gcc_assert (cond == GT_EXPR || cond == LT_EXPR); + if (TREE_CONSTANT (init) && TREE_CONSTANT (final) + && ((cond == GT_EXPR && tree_int_cst_le (init, final)) + || (cond == LT_EXPR && tree_int_cst_le (final, init)))) + return build_int_cst (diff_type, 0); + + tree diff = fold_build2 (minus_code, diff_type, final, init); + + /* Divide diff by the step. + + We could always use CEIL_DIV_EXPR since only non-negative results + correspond to valid number of iterations and the behaviour is + unspecified by the spec otherwise. But we try to get the rounding + right for constant negative values to identify infinite loops + more precisely for better warnings. */ + tree_code div_expr = CEIL_DIV_EXPR; + if (TREE_CONSTANT (diff) && TREE_CONSTANT (step)) + { + bool diff_is_neg = tree_int_cst_lt (diff, size_zero_node); + bool step_is_neg = tree_int_cst_lt (step, size_zero_node); + if ((diff_is_neg && !step_is_neg) + || (!diff_is_neg && step_is_neg)) + div_expr = FLOOR_DIV_EXPR; + } + diff = fold_build2 (div_expr, type, diff, step); return diff; } -/* Return true if the expression representing the number of iterations for - OMP_FOR is a constant expression, false otherwise. */ +/* Return true if the expression representing the number of iterations + for OMP_FOR is a non-negative constant and set ITERATIONS to the + value of that expression. Otherwise, return false. Set INFINITE to + true if the number of iterations was recognized to be infinite. */ bool gomp_for_constant_iterations_p (gomp_for *omp_for, - unsigned HOST_WIDE_INT *iterations) + unsigned HOST_WIDE_INT *iterations, + bool *infinite = NULL) { tree t = gomp_for_number_of_iterations (omp_for, 0); - if (!TREE_CONSTANT (t) - || !tree_fits_uhwi_p (t)) + if (!TREE_CONSTANT (t)) return false; - *iterations = tree_to_uhwi (t); - return true; + if (infinite && + tree_int_cst_lt (t, size_zero_node)) + *infinite = true; + else if (tree_fits_uhwi_p (t)) + { + *iterations = tree_to_uhwi (t); + return true; + } + + return false; } static gimple_seq @@ -525,10 +562,18 @@ full_unroll (gomp_for *omp_for, location_t loc, walk_ctx *ctx ATTRIBUTE_UNUSED) { tree init = gimple_omp_for_initial (omp_for, 0); unsigned HOST_WIDE_INT niter = 0; - if (!gomp_for_constant_iterations_p (omp_for, &niter)) + bool infinite = false; + bool constant = gomp_for_constant_iterations_p (omp_for, &niter, &infinite); + + if (infinite) + { + warning_at (loc, 0, "Cannot apply full unrolling to infinite loop"); + return NULL; + } + if (!constant) { error_at (loc, "Cannot apply full unrolling to loop with " - "non-constant number of iterations"); + "non-constant number of iterations"); return omp_for; } @@ -1595,8 +1640,9 @@ process_omp_for (gomp_for *omp_for, gimple_seq *containing_seq, walk_ctx *ctx) if (!dump_enabled_p () || !(dump_flags & TDF_DETAILS)) return; - dump_printf_loc (MSG_NOTE | MSG_PRIORITY_INTERNALS, transformed, - "Transformed loop: %G\n\n", transformed); + if (transformed) + dump_printf_loc (MSG_NOTE | MSG_PRIORITY_INTERNALS, transformed, + "Transformed loop: %G\n\n", transformed); } /* Traverse SEQ in depth-first order and apply the loop transformation diff --git a/gcc/testsuite/c-c++-common/gomp/loop-transforms/unroll-8.c b/gcc/testsuite/c-c++-common/gomp/loop-transforms/unroll-8.c new file mode 100644 index 00000000000..d49d7c42c87 --- /dev/null +++ b/gcc/testsuite/c-c++-common/gomp/loop-transforms/unroll-8.c @@ -0,0 +1,76 @@ +extern void dummy(int); + +void +test1 () +{ +#pragma omp unroll full /* { dg-warning "Cannot apply full unrolling to infinite loop" } */ + for (int i = 101; i > 100; i++) + dummy (i); +} + + +void +test2 () +{ +#pragma omp unroll full + for (int i = 101; i != 100; i++) + dummy (i); +} + +void +test3 () +{ +#pragma omp unroll full /* { dg-warning "Cannot apply full unrolling to infinite loop" } */ + for (int i = 0; i <= 0; i--) + dummy (i); +} + +void +test4 () +{ +#pragma omp unroll full /* { dg-warning "Cannot apply full unrolling to infinite loop" } */ + for (int i = 101; i > 100; i=i+2) + dummy (i); +} + +void +test5 () +{ +#pragma omp unroll full /* { dg-warning "Cannot apply full unrolling to infinite loop" } */ + for (int i = -101; i < 100; i=i-10) + dummy (i); +} + +void +test6 () +{ +#pragma omp unroll full /* { dg-warning "Cannot apply full unrolling to infinite loop" } */ + for (int i = -101; i < 100; i=i-300) + dummy (i); +} + +void +test7 () +{ +#pragma omp unroll full /* { dg-warning "Cannot apply full unrolling to infinite loop" } */ + for (int i = 101; i > -100; i=i+300) + dummy (i); + + /* Loop does not iterate, hence no warning. */ +#pragma omp unroll full + for (int i = 101; i > 101; i=i+300) + dummy (i); +} + +void +test8 () +{ +#pragma omp unroll full /* { dg-warning "Cannot apply full unrolling to infinite loop" } */ + for (int i = -21; i < -20; i=i-40) + dummy (i); + + /* Loop does not iterate, hence no warning. */ +#pragma omp unroll full + for (int i = -21; i > 20; i=i-40) + dummy (i); +}