This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: PR tree-optimization/45522 (missed constand folding in VRP)
- From: Richard Guenther <rguenther at suse dot de>
- To: Jan Hubicka <hubicka at ucw dot cz>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Sat, 4 Sep 2010 16:07:39 +0200 (CEST)
- Subject: Re: PR tree-optimization/45522 (missed constand folding in VRP)
- References: <20100904134204.GC31380@kam.mff.cuni.cz>
On Sat, 4 Sep 2010, Jan Hubicka wrote:
> 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?
Ok.
Thanks,
Richard.
> 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:
>
>
--
Richard Guenther <rguenther@suse.de>
Novell / SUSE Labs
SUSE LINUX Products GmbH - Nuernberg - AG Nuernberg - HRB 16746 - GF: Markus Rex