From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15278 invoked by alias); 29 Apr 2015 09:53:21 -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 15268 invoked by uid 89); 29 Apr 2015 09:53:21 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.8 required=5.0 tests=AWL,BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RCVD_IN_DNSWL_LOW autolearn=no version=3.3.2 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 (AES256-GCM-SHA384 encrypted) ESMTPS; Wed, 29 Apr 2015 09:53:11 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id D37472E1DAD7 for ; Wed, 29 Apr 2015 11:53:05 +0200 (CEST) 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 2pa0oGE_IB9Y for ; Wed, 29 Apr 2015 11:53:05 +0200 (CEST) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id 532F22E1DADA for ; Wed, 29 Apr 2015 11:53:04 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [patch] Perform anonymous constant propagation during inlining Date: Wed, 29 Apr 2015 10:23:00 -0000 Message-ID: <6476732.lMFodJZTVz@polaris> User-Agent: KMail/4.7.2 (Linux/3.1.10-1.29-desktop; KDE/4.7.2; x86_64; ; ) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart1813000.UGznML6JAQ" Content-Transfer-Encoding: 7Bit X-SW-Source: 2015-04/txt/msg01848.txt.bz2 --nextPart1813000.UGznML6JAQ Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Content-length: 1135 Historically the pragma Inline_Always of GNAT had been implemented in the FE because the RTL inliner and then the Tree inliner weren't invoked at -O0 or powerful enough to inline some constructs. But this approach had drawbacks, especially wrt debug info. These restrictions were gradually lifted and now the pragma is entirely piggybacked on the Tree inliner. This went mostly OK, except for a few cases where intrisinc operations that used to be reasonably handled at -O0 now generate awful code, the typical example being a modulus or division instrinsic by a power-of-2 generating a fully-fledged modulus or division instruction instead of a simple shift. Therefore the attached patch implements anonymous constant propagation in the inliner to fix the code quality regression. Tested on x86_64-suse-linux, OK for the mainline? 2015-04-29 Eric Botcazou * tree-inline.c (remap_gimple_op_r): Do anonymous constant propagation. (copy_bb): Fold conversions of constants immediately. 2015-04-29 Eric Botcazou * gnat.dg/inline12.adb: New test. -- Eric Botcazou --nextPart1813000.UGznML6JAQ Content-Disposition: attachment; filename="inline12.adb" Content-Transfer-Encoding: 7Bit Content-Type: text/x-adasrc; charset="utf-8"; name="inline12.adb" Content-length: 348 -- { dg-do compile } with System.Storage_Elements; use System, System.Storage_Elements; function Inline12 return Natural is A : Address := Inline12'Code_Address; begin while A mod Address'Alignment /= 0 loop A := A + 1; end loop; return Natural (A - Inline12'Code_Address); end; -- { dg-final { scan-assembler-not "mod|div" } } --nextPart1813000.UGznML6JAQ Content-Disposition: attachment; filename="p.diff" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="utf-8"; name="p.diff" Content-length: 1910 Index: tree-inline.c =================================================================== --- tree-inline.c (revision 222439) +++ tree-inline.c (working copy) @@ -898,7 +898,19 @@ remap_gimple_op_r (tree *tp, int *walk_s if (TREE_CODE (*tp) == SSA_NAME) { - *tp = remap_ssa_name (*tp, id); + tree t = remap_ssa_name (*tp, id); + /* Perform anonymous constant propagation, this makes it possible to + generate reasonable code even at -O0 for operators implemented as + inline functions. */ + if (TREE_CODE (t) == SSA_NAME + && SSA_NAME_DEF_STMT (t) + && (!SSA_NAME_VAR (t) || DECL_IGNORED_P (SSA_NAME_VAR (t))) + && gimple_assign_copy_p (SSA_NAME_DEF_STMT (t)) + && is_gimple_min_invariant + (gimple_assign_rhs1 (SSA_NAME_DEF_STMT (t)))) + *tp = gimple_assign_rhs1 (SSA_NAME_DEF_STMT (t)); + else + *tp = t; *walk_subtrees = 0; return NULL; } @@ -1965,7 +1977,7 @@ copy_bb (copy_body_data *id, basic_block /* Statements produced by inlining can be unfolded, especially when we constant propagated some operands. We can't fold - them right now for two reasons: + them right now in the general case for two reasons: 1) folding require SSA_NAME_DEF_STMTs to be correct 2) we can't change function calls to builtins. So we just mark statement for later folding. We mark @@ -1974,7 +1986,10 @@ copy_bb (copy_body_data *id, basic_block foldable indirectly are updated. If this turns out to be expensive, copy_body can be told to watch for nontrivial changes. */ - if (id->statements_to_fold) + if (gimple_assign_cast_p (stmt) + && is_gimple_min_invariant (gimple_assign_rhs1 (stmt))) + fold_stmt (©_gsi); + else if (id->statements_to_fold) id->statements_to_fold->add (stmt); /* We're duplicating a CALL_EXPR. Find any corresponding --nextPart1813000.UGznML6JAQ--