From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 101007 invoked by alias); 27 Nov 2017 11:57:24 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 100997 invoked by uid 89); 27 Nov 2017 11:57:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-8.3 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,KAM_ASCII_DIVIDERS,KAM_NUMSUBJECT,KB_WAM_FROM_NAME_SINGLEWORD,RCVD_IN_BRBL_LASTEXT,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=fes X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 27 Nov 2017 11:57:12 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id E4B0581549; Mon, 27 Nov 2017 12:57:09 +0100 (CET) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id q_wMQj0UMMfq; Mon, 27 Nov 2017 12:57:09 +0100 (CET) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id D7BC38152A; Mon, 27 Nov 2017 12:57:08 +0100 (CET) From: Eric Botcazou To: Richard Biener Cc: gcc-patches@gcc.gnu.org Subject: Re: [patch] Add support for #pragma GCC unroll v2 Date: Mon, 27 Nov 2017 12:32:00 -0000 Message-ID: <3469517.7L1FyOgWi1@polaris> User-Agent: KMail/4.14.10 (Linux/3.16.7-53-desktop; KDE/4.14.9; x86_64; ; ) In-Reply-To: References: <2195708.5NdSF6Gi6B@polaris> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart3526094.zHvWGihNb8" Content-Transfer-Encoding: 7Bit X-SW-Source: 2017-11/txt/msg02289.txt.bz2 This is a multi-part message in MIME format. --nextPart3526094.zHvWGihNb8 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Content-length: 1142 > The middle-end, testsuite and boilerplate changes in the FEs are ok. Thanks. But it turns out that the Ada compiler needs a way to convey a pragma unroll without explicit unrolling factor, because otherwise the RTL unroller will happily try to unroll some loops USHRT_MAX times... Tested on x86_64-suse-linux, applied on the mainline. > Pragma support in the FEs need FE maintainer approval. Yes, I have posted separate patches for the C/C++ and Fortran front-ends. 2017-11-27 Eric Botcazou * cfgloop.h (struct loop): Document usage of USHRT_MAX for unroll. * loop-unroll.c (decide_unroll_constant_iterations): Implement it. (decide_unroll_runtime_iterations): Likewise. (decide_unroll_stupid): Likewise. 2017-11-27 Eric Botcazou * gnat.dg/unroll1.ads: Remove alignment clause. * gnat.dg/unroll2.ads: Likewise. * gnat.dg/unroll3.ads: Likewise. * gnat.dg/unroll1.adb: Remove bogus comment terminator. * gnat.dg/unroll2.adb: Likewise. * gnat.dg/unroll3.adb: Likewise. * gnat.dg/unroll4.ad[sb]: New testcase. * gnat.dg/unroll4_pkg.ads: New helper. -- Eric Botcazou --nextPart3526094.zHvWGihNb8 Content-Disposition: attachment; filename="p.diff" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="p.diff" Content-length: 6519 Index: cfgloop.h =================================================================== --- cfgloop.h (revision 255147) +++ cfgloop.h (working copy) @@ -221,9 +221,10 @@ struct GTY ((chain_next ("%h.next"))) lo /* True if the loop is part of an oacc kernels region. */ unsigned in_oacc_kernels_region : 1; - /* The number of times to unroll the loop. 0, means no information - given, just do what we always do. A value of 1, means don't unroll - the loop. */ + /* The number of times to unroll the loop. 0 means no information given, + just do what we always do. A value of 1 means do not unroll the loop. + A value of USHRT_MAX means unroll with no specific unrolling factor. + Other values means unroll with the given unrolling factor. */ unsigned short unroll; /* For SIMD loops, this is a unique identifier of the loop, referenced Index: loop-unroll.c =================================================================== --- loop-unroll.c (revision 255147) +++ loop-unroll.c (working copy) @@ -395,7 +395,7 @@ decide_unroll_constant_iterations (struc } /* Check for an explicit unrolling factor. */ - if (loop->unroll) + if (loop->unroll > 0 && loop->unroll < USHRT_MAX) { /* However we cannot unroll completely at the RTL level a loop with constant number of iterations; it should have been peeled instead. */ @@ -693,7 +693,7 @@ decide_unroll_runtime_iterations (struct if (targetm.loop_unroll_adjust) nunroll = targetm.loop_unroll_adjust (nunroll, loop); - if (loop->unroll) + if (loop->unroll > 0 && loop->unroll < USHRT_MAX) nunroll = loop->unroll; /* Skip big loops. */ @@ -1177,7 +1177,7 @@ decide_unroll_stupid (struct loop *loop, if (targetm.loop_unroll_adjust) nunroll = targetm.loop_unroll_adjust (nunroll, loop); - if (loop->unroll) + if (loop->unroll > 0 && loop->unroll < USHRT_MAX) nunroll = loop->unroll; /* Skip big loops. */ Index: testsuite/gnat.dg/unroll1.adb =================================================================== --- testsuite/gnat.dg/unroll1.adb (revision 255147) +++ testsuite/gnat.dg/unroll1.adb (working copy) @@ -23,5 +23,5 @@ package body Unroll1 is end Unroll1; --- { dg-final { scan-tree-dump-times "Not unrolling loop .: user didn't want it unrolled completely" 2 "cunrolli" } } */ --- { dg-final { scan-rtl-dump-times "Not unrolling loop, user didn't want it unrolled" 2 "loop2_unroll" } } */ +-- { dg-final { scan-tree-dump-times "Not unrolling loop .: user didn't want it unrolled completely" 2 "cunrolli" } } +-- { dg-final { scan-rtl-dump-times "Not unrolling loop, user didn't want it unrolled" 2 "loop2_unroll" } } Index: testsuite/gnat.dg/unroll1.ads =================================================================== --- testsuite/gnat.dg/unroll1.ads (revision 255147) +++ testsuite/gnat.dg/unroll1.ads (working copy) @@ -1,7 +1,6 @@ package Unroll1 is type Sarray is array (1 .. 4) of Float; - for Sarray'Alignment use 16; function "+" (X, Y : Sarray) return Sarray; procedure Add (X, Y : Sarray; R : out Sarray); Index: testsuite/gnat.dg/unroll2.adb =================================================================== --- testsuite/gnat.dg/unroll2.adb (revision 255147) +++ testsuite/gnat.dg/unroll2.adb (working copy) @@ -23,4 +23,4 @@ package body Unroll2 is end Unroll2; --- { dg-final { scan-tree-dump-times "note: loop with 3 iterations completely unrolled" 2 "cunrolli" } } */ +-- { dg-final { scan-tree-dump-times "note: loop with 3 iterations completely unrolled" 2 "cunrolli" } } Index: testsuite/gnat.dg/unroll2.ads =================================================================== --- testsuite/gnat.dg/unroll2.ads (revision 255147) +++ testsuite/gnat.dg/unroll2.ads (working copy) @@ -1,7 +1,6 @@ package Unroll2 is type Sarray is array (1 .. 4) of Float; - for Sarray'Alignment use 16; function "+" (X, Y : Sarray) return Sarray; procedure Add (X, Y : Sarray; R : out Sarray); Index: testsuite/gnat.dg/unroll3.adb =================================================================== --- testsuite/gnat.dg/unroll3.adb (revision 255147) +++ testsuite/gnat.dg/unroll3.adb (working copy) @@ -23,4 +23,4 @@ package body Unroll3 is end Unroll3; --- { dg-final { scan-tree-dump-times "note: loop with 3 iterations completely unrolled" 2 "cunroll" } } */ +-- { dg-final { scan-tree-dump-times "note: loop with 3 iterations completely unrolled" 2 "cunroll" } } Index: testsuite/gnat.dg/unroll3.ads =================================================================== --- testsuite/gnat.dg/unroll3.ads (revision 255147) +++ testsuite/gnat.dg/unroll3.ads (working copy) @@ -1,7 +1,6 @@ package Unroll3 is type Sarray is array (1 .. 4) of Float; - for Sarray'Alignment use 16; function "+" (X, Y : Sarray) return Sarray; procedure Add (X, Y : Sarray; R : out Sarray); Index: testsuite/gnat.dg/unroll4.adb =================================================================== --- testsuite/gnat.dg/unroll4.adb (revision 0) +++ testsuite/gnat.dg/unroll4.adb (working copy) @@ -0,0 +1,26 @@ +-- { dg-do compile } +-- { dg-options "-O -fdump-rtl-loop2_unroll-details" } + +package body Unroll4 is + + function "+" (X, Y : Sarray) return Sarray is + R : Sarray; + begin + for I in Sarray'Range loop + pragma Loop_Optimize (Unroll); + R(I) := X(I) + Y(I); + end loop; + return R; + end; + + procedure Add (X, Y : Sarray; R : out Sarray) is + begin + for I in Sarray'Range loop + pragma Loop_Optimize (Unroll); + R(I) := X(I) + Y(I); + end loop; + end; + +end Unroll4; + +-- { dg-final { scan-rtl-dump-times "note: loop unrolled 7 times" 2 "loop2_unroll" } } Index: testsuite/gnat.dg/unroll4.ads =================================================================== --- testsuite/gnat.dg/unroll4.ads (revision 0) +++ testsuite/gnat.dg/unroll4.ads (working copy) @@ -0,0 +1,10 @@ +with Unroll4_Pkg; use Unroll4_Pkg; + +package Unroll4 is + + type Sarray is array (1 .. N) of Float; + + function "+" (X, Y : Sarray) return Sarray; + procedure Add (X, Y : Sarray; R : out Sarray); + +end Unroll4; Index: testsuite/gnat.dg/unroll4_pkg.ads =================================================================== --- testsuite/gnat.dg/unroll4_pkg.ads (revision 0) +++ testsuite/gnat.dg/unroll4_pkg.ads (working copy) @@ -0,0 +1,5 @@ +package Unroll4_Pkg is + + function N return Positive; + +end Unroll4_Pkg; --nextPart3526094.zHvWGihNb8--