On Tue, Dec 6, 2011 at 11:00 AM, Amker.Cheng <amker.ch...@gmail.com> wrote:
> On Thu, Dec 1, 2011 at 11:45 PM, Richard Guenther
> <richard.guent...@gmail.com> wrote:
>
>> Well, it's not that easy if you still want to properly do redundant 
>> expression
>> removal on global registers.
>
> Yes, it might be complicate to make PRE fully aware of global register.
> I also found comments in is_gimple_reg which says gcc does not do
> much optimization with register variable at the tree level for now.
>
> Back to this issue, I think it can be fixed by following way without hurting
> redundancy elimination on global register variables:
>
> After insert() being called in pre, in function eliminate() we can check for
> single assignment statement from global register variable to ssa_name.
> If it is the case, we can just skip the elimination operation.
>
> In this way:
> 1, normal redundancy elimination on global registers will not be hurt,
>    since sccvn and pre has already detected the true elimination chances
>    and they will be eliminated afterward in function eliminate;
> 2, the inserted statements(including PHIs) for global register variables
>    will not be marked as NECESSARY in function eliminate and will be
>    deleted in remove_dead_inserted_code;
>
> I attached an example which can illustrates that the normal redundancy does
> get eliminated.
> I will send a patch for review if it worth a discuss. So what do you think?

Well, a patch that extends the fact that eliminate () does not
perform elimination on register copies (via the
!gimple_assign_ssa_name_copy_p (stmt) check) to also cover
DECL_REGISTER decls, like

Index: gcc/tree-ssa-pre.c
===================================================================
--- gcc/tree-ssa-pre.c  (revision 182044)
+++ gcc/tree-ssa-pre.c  (working copy)
@@ -4170,7 +4170,9 @@ eliminate (void)
              && TREE_CODE (gimple_get_lhs (stmt)) == SSA_NAME
              && !gimple_assign_ssa_name_copy_p (stmt)
              && (!gimple_assign_single_p (stmt)
-                 || !is_gimple_min_invariant (gimple_assign_rhs1 (stmt)))
+                 || (!is_gimple_min_invariant (gimple_assign_rhs1 (stmt))
+                     && (gimple_assign_rhs_code (stmt) != VAR_DECL
+                         || !DECL_HARD_REGISTER (gimple_assign_rhs1 (stmt)))))
              && !gimple_has_volatile_ops  (stmt)
              && !has_zero_uses (gimple_get_lhs (stmt)))
            {

would be ok.  But you'd for example still get the insertions done
by PRE (though likely removed again as not needed because
elimination doesn't use them).

Richard.

> Thanks
>
> --
> Best Regards.

Reply via email to