get_ref_base_and_extend based ctor folding
H.J. Lu
hjl.tools@gmail.com
Sat Oct 2 01:48:00 GMT 2010
On Sat, Sep 25, 2010 at 4:09 AM, Jan Hubicka <hubicka@ucw.cz> wrote:
>
> Hi,
> this is my best attempt to make fold_ctor_reference not scary.
> It breaks up implementation into fold_string_cst_ctor_reference,
> fold_array_ctor_reference, and fold_nonarray_ctor_reference
> and I've addressed the comments (i.e. reorganized array folding
> to first compute index and compare with it and introduced more
> comments and temporaries in aggregate folding).
>
> I also removed most of strange view convert logic - now we either
> need types to match in the sense of useless_type_conversion_p
> or we need to see scalar and try to introduce view_convert_expr.
>
> Later we can add more fun via reinterpretting natural expr
> or by teaching fold_string_cst_ctor_reference to play view_convert_expr
> games, but it is not important.
>
> Finally i got rid compares with size of access type to cure bitfields.
> Instead when looking into arrays or structures, I compare with element
> size (or field_decl_size) to see if field is large enough to cover whole
> access.
>
> I did not ruled out bitfields since whole code has no special code for
> them now, but I defnitly can and update testcase if it makes things safer
> too. I regtested with that variant too and it passes as well.
>
> Bootstrapped/regtested x86_64-linux, OK?
> Honza
>
> /* { dg-do compile } */
> /* { dg-options "-O -fdump-tree-ccp1" } */
>
>
> static const char a[5]="t";
> static const int b[5]={1,2};
> static const struct a {int a : 6; int b : 6;} c = {5,9};
> test()
> {
> return a[2]+b[1]+b[3]+c.b;
> }
> /* { dg-final { scan-tree-dump "return 11;" "ccp1" } } */
> /* { dg-final { cleanup-tree-dump "ccp1" } } */
>
> * tree-ssa-ccp.c (fold_ctor_reference): New function.
> (fold_string_cst_ctor_reference, fold_array_ctor_reference,
> fold_nonarray_ctor_reference): New functions.
> (fold_const_aggregate_ref): Use it.
This caused:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45860
H.J.
More information about the Gcc-patches
mailing list