This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Plug optimization hole in constant folder
- From: "Richard Guenther" <richard dot guenther at gmail dot com>
- To: "Eric Botcazou" <ebotcazou at adacore dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 17 Sep 2007 21:03:22 +0200
- Subject: Re: [PATCH] Plug optimization hole in constant folder
- References: <200709171646.04125.ebotcazou@adacore.com>
On 9/17/07, Eric Botcazou <ebotcazou@adacore.com> wrote:
> Hi,
>
> This is end-of-stage-2 material but plugs an obvious hole in the constant
> folder. In fold_ternary:
>
> case COMPONENT_REF:
> if (TREE_CODE (arg0) == CONSTRUCTOR
> && ! type_contains_placeholder_p (TREE_TYPE (arg0)))
> {
> unsigned HOST_WIDE_INT idx;
> tree field, value;
> FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (arg0), idx, field, value)
> if (field == arg1)
> return value;
> }
> return NULL_TREE;
>
> but the couterpart for ARRAY_REF is nowhere to be found. As a result:
>
> package P is
>
> type R is record
> I : Integer;
> end record;
>
> f1 : constant R := (I=>1);
> f2 : integer renames f1.I;
>
> b : boolean := f2 = 1;
>
> end P;
>
> is entirely optimized at compile time
>
> p__b:
> .byte 1
>
> while
>
> package P is
>
> type A is array (1..1) of Integer;
> f1 : constant A := (1=>1);
> f2 : integer renames f1(1);
>
> b : boolean := f2 = 1;
>
> end P;
>
> is not.
>
>
> Bootstrapped/regtested on i586-suse-linux, OK for mainline?
It looks straight-forward, but I fear of potential impact on compile-time.
Can you at least restrict the transformation to indices of INTEGER_CST
kind? Can you check if it is possible to use binary search on the
array constructor (I seem to remember we keep the elements sorted)?
Thanks,
Richard.
> 2007-09-17 Eric Botcazou <ebotcazou@adacore.com>
>
> * fold-const.c (fold) <ARRAY_REF>: New case. Try to fold
> reference in constructor with non self-referential type.
> ada/
> * utils2.c (build_binary_op): Fold ARRAY_REF and ARRAY_RANGE_REF too.
>
>
> 2007-09-17 Eric Botcazou <ebotcazou@adacore.com>
>
> * gnat.dg/specs/static_initializer2.ads: New testcase.
>
>
> --
> Eric Botcazou
>
>