[PATCH] Extend store ccp
Diego Novillo
dnovillo@redhat.com
Thu Apr 26 15:04:00 GMT 2007
Revital1 Eres wrote on 03/23/07 01:26:
> This patch enhance store ccp to propagate constants from stores to
> loads when the previous implementation failed due to alias uncertainty.
> The testcase attached demonstrates this optimization:
>
> S[5].x = 0;
> S[5].y = 0;
>
> x = S[5].x;
> y = S[5].y;
>
> Previously x = S[5].x; failed to be replaced with x = 0. This patch
> fixes this problem by allowing the propagation of constants if all the
> stores in the alias group are initialized with the same constant.
>
We could do one better. While following the use-def chain, we could ask if the LHS of the assignment overlaps the RHS that we are trying to replace. So:
1 # S_3 = VDEF <S_1>
2 S[5].x = 0;
3
4 # S_4 = VDEF <S_3>
5 S[5].y = x_9;
6
7 # VUSE <S_4>
8 x = S[5].x;
9
10 # VUSE <S_4>
11 y = S[5].y;
>From statement #8 you go to statement #4, since a store to S[5].y does
not affect S[5].x (we can use nonoverlapping_component_refs_p as a
starting point or access_can_touch_variable, for instance).
This will improve both copy and constant propagation.
Another problem with the patch is that you are doing this too late.
Why not do this *during* propagation? In this case, you would allow S_4 to assume the lattice value of 0 and use it during propagation.
> +/* Return the defining stmt for the rhs of STMT following the virtual
> + use-def chains if all the VDEFs of this rhs up until the defining stmt
> + initialized by the same constant value as CONST_VAL. Returns the
> + MODIFY_EXPR stmt which lhs is equal to the rhs of STMT or NULL_TREE
> + if no such stmt can be found. */
> +static tree
> +get_def_of_stmt_rhs (tree stmt, tree const_val)
Vertical spacing.
> +static bool
> +do_store_ccp (void)
> +{
Missing documentation.
> + return (flag_tree_store_ccp != 0 && flag_tree_ccp != 0);
> +}
> +
> +/* Return true if rhs of STMT has a known VUSE and all
> + it's VDEFs in the virtual use-def chain (up until the insn
s/it's/its/
> + which created it's SSA_NAME) have the same constant value as
Likewise.
> + recorded in VAL. */
> +bool
> +all_vdef_have_same_lattice_const_value (prop_value_t* val, tree stmt)
Vertical spacing after comment.
> bool
> -substitute_and_fold (prop_value_t *prop_value, bool use_ranges_p)
> +substitute_and_fold (prop_value_t *prop_value, bool use_ranges_p,
> + bool aggressive_store_ccp_p)
The aggressive_store_ccp_p argument is not necessary.
More information about the Gcc-patches
mailing list