[patch] Perform anonymous constant propagation during inlining

Richard Biener richard.guenther@gmail.com
Tue May 12 08:46:00 GMT 2015


On Mon, May 11, 2015 at 4:05 PM, Eric Botcazou <ebotcazou@adacore.com> wrote:
>> >Would you be OK with a slight variation of your earlier idea, i.e.
>> >calling fold_stmt with a specific valueizer from fold_marked_statements
>> >instead of the implicit no_follow_ssa_edges in the inliner?  Something
>> >like:
>> >
>> >tree
>> >follow_anonymous_single_use_edges (tree val)
>> >{
>> >
>> >  if (TREE_CODE (val) == SSA_NAME
>> >
>> >      && (!SSA_NAME_VAR (val) || DECL_IGNORED_P (SSA_NAME_VAR
>> >      (var)))
>> >      && has_single_use (val))
>> >
>> >    return val
>> >
>> >  return NULL_TREE;
>> >
>> >}
>>
>> Yes, that works for me as well.
>
> But not for GCC. :-)  The propagation per se works but, since the statement is
> not folded in the end, no replacement is made at all...
>
> So we're back to square one and anonymous constant propagation seems to be the
> only way out at -O0.  The attached patch implements it in a less hackish way
> (and enables it unconditionally when optimizing as suggested by Jan) by doing
> it just before invoking fold_stmt on the marked statements so this should make
> folding more effective in the process.
>
> Tested (compiler only) on x86_64-suse-linux, OK for the mainline?

+  if (replaced && gimple_assign_single_p (stmt))
+    {
+      tree rhs = gimple_assign_rhs1 (stmt);
+
+      if (TREE_CODE (rhs) == ADDR_EXPR)
+       recompute_tree_invariant_for_addr_expr (rhs);
+    }

this needs to handle all non-PHI stmt kinds (asms and calls), see
tree-cfg.c:replace_uses_by
(maybe factor out a recompute_tree_invariant_for_gimple_ops).

Looking at the whole thing I think it might be better to

 a) _not_ propagate parameter values during the stmt copies
 b) _not_ mark any stmts for folding
 c) at fold_marked_stmts time instead treat the incoming parameter
     mappings (which param setup "inlined" as param_1 = value1; etc...)
     as a seed for the worklist of a simple SSA propagator doing sth like

 while (!bitmap_empty (worklist))
   {
     tree name = ssa_name (bitmap_first_bit (worklist));
     gimple stmt = SSA_NAME_DEF_STMT (name);
     gcc_assert (gimple_assign_single_p (stmt)
                   && is_gimple_min_invariant (gimple_assign_rhs1 (stmt)));
     FOR_EACH_IMM_USE_STMT (name)
        {
         FOR_EACH_IMM_USE_ON_STMT (..)
            SET_USE (...)
         fold_stmt (use_stmt);
           if (gimple_assing_single_p (use_stmt)
               && is_gimple_min_invariant (gimple_assign_rhs1 (use_stmt)))
            bitmap_set_bit (worklist, SSA_NAME_VERSION
(gimple_assign_lhs (use_stmt)));
        }
     bitmap_clear_bit (SSA_NAME_VERSION (name));
     /* remove 'stmt' if we replaced all uses - properly generating
debug stmts  */
   }

appropriately restricted for !optimize and eventually also propagating
copies for !optimize.

This should make sure we keep all stmts properly folded after inlining
and it should more
reliably propagate constants exposed by inlining (it should be cheaper
than a full SSA CCP
pass because we likely visit less stmts by just taking constant
parameters as propagation
sources).

Richard.

>
> 2015-05-11  Eric Botcazou  <ebotcazou@adacore.com>
>
>         * tree-inline.c: Include tree-ssa-propagate.h.
>         (replace_constant_uses_in): New function.
>         (fold_marked_statements): Call it before folding the statement.
>
>         * gimple-expr.h (is_gimple_constant): Reorder.
>         * tree-ssa-propagate.c (before_dom_children): Use inline accessor.
>
>
> --
> Eric Botcazou



More information about the Gcc-patches mailing list