From patchwork Tue Sep 7 14:39:53 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 64027 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 00738B6EEA for ; Wed, 8 Sep 2010 01:33:52 +1000 (EST) Received: (qmail 21237 invoked by alias); 7 Sep 2010 14:41:07 -0000 Received: (qmail 20929 invoked by uid 22791); 7 Sep 2010 14:40:51 -0000 X-SWARE-Spam-Status: No, hits=-1.7 required=5.0 tests=AWL, BAYES_00, TW_CV, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from nikam-dmz.ms.mff.cuni.cz (HELO nikam.ms.mff.cuni.cz) (195.113.20.16) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 07 Sep 2010 14:40:00 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 391619AC93C; Tue, 7 Sep 2010 16:39:53 +0200 (CEST) Date: Tue, 7 Sep 2010 16:39:53 +0200 From: Jan Hubicka To: Richard Guenther Cc: Jan Hubicka , gcc-patches@gcc.gnu.org Subject: Re: Teach sccvn about constant vars Message-ID: <20100907143953.GF21528@kam.mff.cuni.cz> References: <20100904211313.GE31380@kam.mff.cuni.cz> <20100904231611.GA17338@atrey.karlin.mff.cuni.cz> <20100906173204.GB21528@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.18 (2008-05-17) 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, this patch fixes the ignored low_bound in array_ref folding and converts arithmetics to double_int. Note that the code (without the low_bound bug) exist in another two copies - in fold_read_from_constant_string and in expr.c I hope to remove the expr.c code by end of week (we need to process the remaining sccvn patch and should be there). In expr.c I can also put in the INTEGER_CST code but since this is used by frontend too we sould miss optimization when lower bound and index are variables. So I guess I can keep the busy operation there and remove the call from tree-ssa-ccp that should be redundant now. Boostrapped/regtested x86_64, OK? Honza * tree-ssa-ccp.c (fold_const_aggregate_ref): Fix handling of array_ref_low_bound in string access folding. Index: tree-ssa-ccp.c =================================================================== --- tree-ssa-ccp.c (revision 163947) +++ tree-ssa-ccp.c (working copy) @@ -1398,14 +1398,27 @@ fold_const_aggregate_ref (tree t) } /* Fold read from constant string. */ - if (TREE_CODE (ctor) == STRING_CST) + if (TREE_CODE (ctor) == STRING_CST + && TREE_CODE (idx) == INTEGER_CST) { + tree low_bound = array_ref_low_bound (t); + double_int low_bound_cst; + double_int index_cst; + double_int length_cst; + bool signed_p = TYPE_UNSIGNED (TREE_TYPE (idx)); + + if (TREE_CODE (low_bound) != INTEGER_CST) + return NULL_TREE; + low_bound_cst = tree_to_double_int (low_bound); + index_cst = tree_to_double_int (idx); + length_cst = uhwi_to_double_int (TREE_STRING_LENGTH (ctor)); + double_int_sub (index_cst, low_bound_cst); if ((TYPE_MODE (TREE_TYPE (t)) == TYPE_MODE (TREE_TYPE (TREE_TYPE (ctor)))) && (GET_MODE_CLASS (TYPE_MODE (TREE_TYPE (TREE_TYPE (ctor)))) == MODE_INT) && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (TREE_TYPE (ctor)))) == 1 - && compare_tree_int (idx, TREE_STRING_LENGTH (ctor)) < 0) + && double_int_cmp (index_cst, length_cst, signed_p) < 0) return build_int_cst_type (TREE_TYPE (t), (TREE_STRING_POINTER (ctor) [TREE_INT_CST_LOW (idx)]));