public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Eric Botcazou <ebotcazou@adacore.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [patch] Perform anonymous constant propagation during inlining
Date: Tue, 12 May 2015 08:46:00 -0000	[thread overview]
Message-ID: <CAFiYyc2KqRb1Aryzgwwx1eqWLCB9Qj_AfNL-MS9JkspQ4EWGrA@mail.gmail.com> (raw)
In-Reply-To: <1725052.qXkxHEI06s@polaris>

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

  reply	other threads:[~2015-05-12  8:26 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-29 10:23 Eric Botcazou
2015-04-29 12:06 ` Richard Biener
2015-05-01 10:29   ` Eric Botcazou
2015-05-01 14:19     ` Richard Biener
2015-05-01 16:44       ` Eric Botcazou
2015-05-01 18:11         ` Eric Botcazou
2015-05-04  8:46           ` Richard Biener
2015-05-04  9:32             ` Eric Botcazou
2015-05-04 21:40           ` Eric Botcazou
2015-05-05  5:43             ` Richard Biener
2015-05-11 14:07               ` Eric Botcazou
2015-05-12  8:46                 ` Richard Biener [this message]
2015-04-29 13:29 ` Jan Hubicka
2015-04-29 13:50   ` Richard Biener
2015-04-29 14:31     ` Jan Hubicka

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFiYyc2KqRb1Aryzgwwx1eqWLCB9Qj_AfNL-MS9JkspQ4EWGrA@mail.gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=ebotcazou@adacore.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).