From patchwork Sat Sep 4 13:42:04 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Hubicka X-Patchwork-Id: 63776 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 B03B3B7148 for ; Sat, 4 Sep 2010 23:42:14 +1000 (EST) Received: (qmail 28516 invoked by alias); 4 Sep 2010 13:42:12 -0000 Received: (qmail 28508 invoked by uid 22791); 4 Sep 2010 13:42:11 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL, BAYES_00, 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; Sat, 04 Sep 2010 13:42:07 +0000 Received: by nikam.ms.mff.cuni.cz (Postfix, from userid 16202) id 000F99AC9E8; Sat, 4 Sep 2010 15:42:04 +0200 (CEST) Date: Sat, 4 Sep 2010 15:42:04 +0200 From: Jan Hubicka To: gcc-patches@gcc.gnu.org, rguenther@suse.de Subject: PR tree-optimization/45522 (missed constand folding in VRP) Message-ID: <20100904134204.GC31380@kam.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline 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 missed folding of tree_code_type[6] into 2 in the testcase attached. The problem is that the constant is discovered by VRP, not CCP and gimple_fold makes no attempt to fold the constant vars references into constants except for string. Moving code folding strings into fold_const_aggregate_ref is also needed to avoid one missed constant folding during Ada bootstrap I don't know how to produce testcase for. Bootstrapped/regtested x86_64-linux, OK? Honza /* { dg-do compile } */ /* { dg-options "-O2 -fdump-tree-optimized" } */ typedef const union tree_node *const_tree; typedef struct { } double_int; double_int double_int_zext (double_int, unsigned); enum tree_code { ERROR_MARK, IDENTIFIER_NODE, TREE_LIST, BLOCK, ENUMERAL_TYPE, BOOLEAN_TYPE, INTEGER_TYPE, ARRAY_TYPE, INTEGER_CST, VAR_DECL, PARM_DECL, RESULT_DECL, }; enum tree_code_class { tcc_exceptional, tcc_constant, tcc_type, tcc_declaration, tcc_reference, }; struct tree_base { __extension__ enum tree_code code:16; unsigned unsigned_flag:1; }; struct tree_type { unsigned int precision:10; union tree_type_symtab { } symtab; }; union tree_node { struct tree_base base; struct tree_type type; }; const enum tree_code_class tree_code_type[] = { tcc_exceptional, 1, 0, 0, 0, 0, 2, }; int_fits_type_p (const_tree c, const_tree type) { double_int dc, dd; { if (((enum tree_code) (type)->base.code) == INTEGER_TYPE && (( { __typeof (type) __t = (type); if (tree_code_type [(int) (((enum tree_code) (__t)-> base. code))] != (tcc_type)) tree_class_check_failed (__t, __FUNCTION__); __t;})-> base. unsigned_flag)) dd = double_int_zext (dd, (( { __typeof (type) __t = (type); if (tree_code_type [(int) (((enum tree_code) (__t)->base. code))] != (tcc_type)) tree_class_check_failed (__t, __FUNCTION__); __t;} )->type.precision)); } } /* The switch should be switch converted and later constant propagated. */ /* { dg-final { scan-tree-dump-not "tree_code_type.6" "optimized"} } */ /* { dg-final { cleanup-tree-dump "optimized" } } */ * gimple-fold.c (maybe_fold_reference): Use fold_const_aggregate_ref. * tree-ssa-ccp.c (fold_const_aggregate_ref): Use fold_read_from_constant_string. Index: gimple-fold.c =================================================================== --- gimple-fold.c (revision 163859) +++ gimple-fold.c (working copy) @@ -462,14 +474,11 @@ static tree maybe_fold_reference (tree expr, bool is_lhs) { tree *t = &expr; + tree result; - if (TREE_CODE (expr) == ARRAY_REF - && !is_lhs) - { - tree tem = fold_read_from_constant_string (expr); - if (tem) - return tem; - } + if (!is_lhs + && (result = fold_const_aggregate_ref (expr))) + return result; /* ??? We might want to open-code the relevant remaining cases to avoid using the generic fold. */ Index: tree-ssa-ccp.c =================================================================== --- tree-ssa-ccp.c (revision 163859) +++ tree-ssa-ccp.c (working copy) @@ -1325,6 +1325,10 @@ fold_const_aggregate_ref (tree t) if (TREE_CODE_CLASS (TREE_CODE (t)) == tcc_declaration) return get_symbol_constant_value (t); + tem = fold_read_from_constant_string (t); + if (tem) + return tem; + switch (TREE_CODE (t)) { case ARRAY_REF: