From patchwork Sat Dec 7 13:53:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 1205447 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-515406-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=netcologne.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="te/a5E7c"; dkim=pass (2048-bit key; unprotected) header.d=netcologne.de header.i=@netcologne.de header.b="om6Z0xWT"; 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 47VWCB0yMVz9sPL for ; Sun, 8 Dec 2019 00:53: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 :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=QcC/jjpDZbFUlHK3N++YS15UAVu0mhTGbXmPQGW2wtMXQWSomv VyJ5XH1ogj5oWDXWqYEpNS4TDFEuaPeqNjxSq3MKTjNqIwjGv7Ga112TQUsb67uM fujx/1uQ4oVqNJKYQPAs7H1GgN8DO5lhgnc0hDyn5PYGxg1uslI7i/6tM= 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 :from:subject:message-id:date:mime-version:content-type; s= default; bh=BnwBp864NpVwfgYgGEsJ/S5Il3g=; b=te/a5E7cNBEKESI9pIyd RiTUnUFIuCzwJKToRQ+zFn1r7TCU81rThVMp1wuFPwwt5cidZ5Kgtgeo5udZ+055 kGQA+5v+YGTbJEHY6VngQNAScqimvseZPsb7kxfyGFlGQJiPAY0pqlKpVvkThgD1 qkMy5cWPvXUIuYhTGpw5GAM= Received: (qmail 40754 invoked by alias); 7 Dec 2019 13:53:47 -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 40739 invoked by uid 89); 7 Dec 2019 13:53:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-16.8 required=5.0 tests=BAYES_00, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy=Enum, gfc_expr, unpacking, 1928 X-HELO: cc-smtpout3.netcologne.de Received: from cc-smtpout3.netcologne.de (HELO cc-smtpout3.netcologne.de) (89.1.8.213) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 07 Dec 2019 13:53:44 +0000 Received: from cc-smtpin3.netcologne.de (cc-smtpin3.netcologne.de [89.1.8.203]) by cc-smtpout3.netcologne.de (Postfix) with ESMTP id 5EBBF126B2; Sat, 7 Dec 2019 14:53:41 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=netcologne.de; s=nc1116a; t=1575726821; bh=2k8ILx5H34CO8vhj/72hn/fE8cvQgKwGhBiaIfH0wU4=; h=To:From:Subject:Message-ID:Date:From; b=om6Z0xWTZpBcVDvz4yiWuzIIWkFRbBq1jXgIvvdu8K860c2HvtzY15+NQyS7ttDT4 4rzXIZh8rLZMAxsG6m661/qANHeshtVl4dsl/SBeslAO5BxD+TRjWIHGMt15cyxDEe xsx+taP7Iqg+cV77bL+N7MqLd9KulcN5Bm+tTeaJ6ABaFmWDy3ILeM6xLcXlFNGaGw u02p/tSqxegQm2ZW+FsFNyIVbkOzhnmfJ/AmE3SMtn8nT/kBURexz6RpgnwSYNQas4 9VkzbgokCIyOWfFgje3k5SxbCpXq6oQHHb0I3jbfgRH90w93zURopN6QGU3keRwQz+ moa3QdRkRjU5A== Received: from localhost (localhost [127.0.0.1]) by cc-smtpin3.netcologne.de (Postfix) with ESMTP id 50CF411ED5; Sat, 7 Dec 2019 14:53:41 +0100 (CET) Received: from [2001:4dd7:c4e0:0:7285:c2ff:fe6c:992d] (helo=cc-smtpin3.netcologne.de) by localhost with ESMTP (eXpurgate 4.11.6) (envelope-from ) id 5debaee5-7104-7f0000012729-7f000001ce9a-1 for ; Sat, 07 Dec 2019 14:53:41 +0100 Received: from [IPv6:2001:4dd7:c4e0:0:7285:c2ff:fe6c:992d] (2001-4dd7-c4e0-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de [IPv6:2001:4dd7:c4e0:0:7285:c2ff:fe6c:992d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by cc-smtpin3.netcologne.de (Postfix) with ESMTPSA; Sat, 7 Dec 2019 14:53:40 +0100 (CET) To: "fortran@gcc.gnu.org" , gcc-patches From: Thomas Koenig Subject: [patch, fortran] Introduce -finline-pack Message-ID: <0393d2b1-849e-e4d4-b505-7f6ed3d52c89@netcologne.de> Date: Sat, 7 Dec 2019 14:53:39 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.2 MIME-Version: 1.0 Hello world, the attached patch introduces a new option, -finline-pack. Since the fix for PR88821, we now do inline packing of arguments (if required) via the scalarizer, instead of using _gfortran_internal_[un]pack when optimizing, but not when optimizing for size. This introduces (really) large performance gains for some test cases because now the middle end can see through the packing. On the other hand, for test cases which do a _lot_ of this, compile time and code size can increase by quite a bit. So, this patch introduces an option to control that behavior, so that people can turn it off on a by-file basis if they don't want it. OK for trunk? Regards Thomas Introduce -finline-pack. 2019-12-07 Thomas Koenig PR middle-end/91512 PR fortran/92738 * invoke.texi: Document -finline-pack. * lang.opt: Add -finline-pack. * options.c (gfc_post_options): Handle -finline-pack. * trans-array.c (gfc_conv_array_parameter): Use flag_inline_pack instead of checking for optimize and optimize_size. 2019-12-07 Thomas Koenig PR middle-end/91512 PR fortran/92738 * gfortran.dg/inline_pack_25.f90: New test. Index: invoke.texi =================================================================== --- invoke.texi (Revision 279064) +++ invoke.texi (Arbeitskopie) @@ -192,8 +192,9 @@ and warnings}. -ffrontend-loop-interchange -ffrontend-optimize @gol -finit-character=@var{n} -finit-integer=@var{n} -finit-local-zero @gol -finit-derived -finit-logical=@var{} @gol --finit-real=@var{} @gol --finline-matmul-limit=@var{n} -fmax-array-constructor=@var{n} @gol +-finit-real=@var{} +-finline-matmul-limit=@var{n} @gol +-finline-pack -fmax-array-constructor=@var{n} @gol -fmax-stack-var-size=@var{n} -fno-align-commons -fno-automatic @gol -fno-protect-parens -fno-underscoring -fsecond-underscore @gol -fpack-derived -frealloc-lhs -frecursive -frepack-arrays @gol @@ -1779,6 +1780,34 @@ compiled with the @option{-fshort-enums} option. GNU Fortran choose the smallest @code{INTEGER} kind a given enumerator set will fit in, and give all its enumerators this kind. +@item -finline-pack +@opindex @code{finline-pack} +When passing an assumed-shape argument of a procedure as actual +argument to an assumed-size or explicit size or as argument to a +procedure that does not have an explicit interface, the argument may +have to be packed, that is put into contiguous memory. An example is +the call to @code{foo} in +@smallexample + subroutine foo(a) + real, dimension(*) :: a + end subroutine foo + subroutine bar(b) + real, dimension(:) :: b + call foo(b) + end subroutine bar +@end smallexample + +When @option{-finline-pack} is in effect, this packing will be +performed by inline code. This allows for more optimization while +increasing code size. + +@option{-finlie-pack} is implied by any of the @option{-O} options +except when optimizing for size via @option{-Os}. If the code +contains a very large number of argument that have to be packed, code +size and also compilation time may become excessive. If that is the +case, it may be better to disable this option. Instances of packing +can be found by using by using @option{-Warray-temporaries}. + @item -fexternal-blas @opindex @code{fexternal-blas} This option will make @command{gfortran} generate calls to BLAS functions Index: lang.opt =================================================================== --- lang.opt (Revision 279064) +++ lang.opt (Arbeitskopie) @@ -647,6 +647,10 @@ Enum(gfc_init_local_real) String(inf) Value(GFC_IN EnumValue Enum(gfc_init_local_real) String(-inf) Value(GFC_INIT_REAL_NEG_INF) +finline-pack +Fortran Var(flag_inline_pack) Init(-1) +-finline-pack Perform argument packing inline + finline-matmul-limit= Fortran RejectNegative Joined UInteger Var(flag_inline_matmul_limit) Init(-1) -finline-matmul-limit= Specify the size of the largest matrix for which matmul will be inlined. Index: options.c =================================================================== --- options.c (Revision 279064) +++ options.c (Arbeitskopie) @@ -467,6 +467,11 @@ gfc_post_options (const char **pfilename) if (flag_frontend_loop_interchange == -1) flag_frontend_loop_interchange = optimize; + /* Do inline packing by default if optimizing, but not if + optimizing for size. */ + if (flag_inline_pack == -1) + flag_inline_pack = optimize && !optimize_size; + if (flag_max_array_constructor < 65535) flag_max_array_constructor = 65535; Index: trans-array.c =================================================================== --- trans-array.c (Revision 279064) +++ trans-array.c (Arbeitskopie) @@ -8139,7 +8139,7 @@ gfc_conv_array_parameter (gfc_se * se, gfc_expr * making the packing and unpacking operation visible to the optimizers. */ - if (g77 && optimize && !optimize_size && expr->expr_type == EXPR_VARIABLE + if (g77 && flag_inline_pack && expr->expr_type == EXPR_VARIABLE && !is_pointer (expr) && ! gfc_has_dimen_vector_ref (expr) && (fsym == NULL || fsym->ts.type != BT_ASSUMED)) {