This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Plug optimization hole in constant folder


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
>
>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]