From patchwork Tue Aug 17 17:18:52 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 61942 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 141D4B6EE8 for ; Wed, 18 Aug 2010 03:18:46 +1000 (EST) Received: (qmail 17820 invoked by alias); 17 Aug 2010 17:18:43 -0000 Received: (qmail 17809 invoked by uid 22791); 17 Aug 2010 17:18:42 -0000 X-SWARE-Spam-Status: No, hits=-6.1 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 17 Aug 2010 17:18:37 +0000 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o7HHIZRs000445 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 17 Aug 2010 13:18:35 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [10.16.42.4]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o7HHIYBh010889 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 17 Aug 2010 13:18:35 -0400 Received: from tyan-ft48-01.lab.bos.redhat.com (tyan-ft48-01.lab.bos.redhat.com [127.0.0.1]) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4) with ESMTP id o7HHIqP6031905 for ; Tue, 17 Aug 2010 19:18:53 +0200 Received: (from jakub@localhost) by tyan-ft48-01.lab.bos.redhat.com (8.14.4/8.14.4/Submit) id o7HHIqHQ031187 for gcc-patches@gcc.gnu.org; Tue, 17 Aug 2010 19:18:52 +0200 Date: Tue, 17 Aug 2010 19:18:52 +0200 From: Jakub Jelinek To: gcc-patches@gcc.gnu.org Subject: [PATCH] Make host_integerp pure and inline tree_low_cst Message-ID: <20100817171851.GG702@tyan-ft48-01.lab.bos.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-12-10) X-IsSubscribed: yes 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 Hi! In many places we call host_integerp and if it succeeds, call tree_low_cst, which again calls host_integerp. The following patch makes host_integerp pure when not doing tree checking (otherwise it can fail if t's type is error_mark_node or some other non-type) and inlines tree_low_cst in that case too. Tested with both --disable-checking and --enable-checking=release. With the former obviously .text section shrunk, with release checking it grew tiny bit: [1] [2] .text size cc1plus -m64 before 281 269 0x730a3c cc1plus -m64 after 417 7 0x73143c cc1plus -m32 before 274 275 0x6c7ca0 cc1plus -m32 after 411 10 0x6c7f10 [1] number of call host_integerp insns [2] number of call tree_low_cst insns As can be seen from the numbers, in more than half of the cases gcc actually has been able to optimize that gcc_assert from the inline tree_low_cst away. Ok for trunk? 2010-08-17 Jakub Jelinek * tree.h (host_integerp): Add ATTRIBUTE_PURE when not ENABLE_TREE_CHECKING. (tree_low_cst): Add inline version for !ENABLE_TREE_CHECKING and GCC >= 4.3. Jakub --- gcc/tree.h.jj 2010-08-16 19:24:24.000000000 +0200 +++ gcc/tree.h 2010-08-17 16:14:59.000000000 +0200 @@ -4099,8 +4099,20 @@ extern int attribute_list_contained (con extern int tree_int_cst_equal (const_tree, const_tree); extern int tree_int_cst_lt (const_tree, const_tree); extern int tree_int_cst_compare (const_tree, const_tree); -extern int host_integerp (const_tree, int); +extern int host_integerp (const_tree, int) +#ifndef ENABLE_TREE_CHECKING + ATTRIBUTE_PURE /* host_integerp is pure only when checking is disabled. */ +#endif + ; extern HOST_WIDE_INT tree_low_cst (const_tree, int); +#if !defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 4003) +extern inline __attribute__ ((__gnu_inline__)) HOST_WIDE_INT +tree_low_cst (const_tree t, int pos) +{ + gcc_assert (host_integerp (t, pos)); + return TREE_INT_CST_LOW (t); +} +#endif extern int tree_int_cst_msb (const_tree); extern int tree_int_cst_sgn (const_tree); extern int tree_int_cst_sign_bit (const_tree);