public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Michael Matz <matz@suse.de>
Cc: Thomas Schwinge <thomas@codesourcery.com>,
	GCC Development <gcc@gcc.gnu.org>
Subject: Re: 'walk_stmt_load_store_addr_ops' for non-'gimple_assign_single_p (stmt)'
Date: Wed, 17 Mar 2021 08:42:19 +0100	[thread overview]
Message-ID: <CAFiYyc2Eu1OhkPyZbxxuW-S-PtD5NESxJ1Fgm9DffsBCBf8+jA@mail.gmail.com> (raw)
In-Reply-To: <alpine.LSU.2.20.2103161508390.446@wotan.suse.de>

On Tue, Mar 16, 2021 at 4:25 PM Michael Matz <matz@suse.de> wrote:
>
> Hello,
>
> On Tue, 16 Mar 2021, Thomas Schwinge wrote:
>
> > >>Indeed, given (Fortran) 'zzz = 1', we produce GIMPLE:
> > >>
> > >>    gimple_assign <real_cst, zzz, 1.0e+0, NULL, NULL>
> > >>
> > >>..., and calling 'walk_stmt_load_store_addr_ops' on that, I see, as
> > >>expected, the 'visit_store' callback invoked, with 'rhs' and 'arg':
> > >>'<var_decl zzz>'.
> > >>
> > >>However, given (Fortran) 'zzz = r + r2', we produce GIMPLE:
> > >>
> > >>    gimple_assign <plus_expr, zzz, r, r2, NULL>
>
> But that's pre-ssa form.  After writing into SSA 'zzz' will be replaced by
> an SSA name, and the actual store into 'zzz' will happen in a store
> instruction.
>
> > >>..., and calling 'walk_stmt_load_store_addr_ops' on that, I see,
> > >>unexpectedly, no callback at all invoked: neither 'visit_load', nor
> > >>'visit_store' (nor 'visit_address', obviously).
> > >
> > > The variables involved are registers. You only get called on memory operands.
> >
> > How would I have told that from the 'walk_stmt_load_store_addr_ops'
> > function description?  (How to improve that one "to reflect relatity"?)
> >
> > But 'zzz' surely is the same in 'zzz = 1' vs. 'zzz = r + r2' -- for the
> > former I *do* see the 'visit_store' callback invoked, for the latter I
> > don't?
>
> The walk_gimple functions are intended to be used on the SSA form of
> gimple (i.e. the one that it is in most of the time).

Actually they are fine to use pre-SSA.  They just even pre-SSA distinguish
between registers and memory.  That's what gimplification honors as well,
in 'zzz = r + r2'  all operands are registers, otherwise GIMPLE requires loads
and stores split into separate stmts not doing any computation.

It's just less obivous in the dumps (compared to SSA name dumping).

Richard.

>  And in that it's
> not the case that 'zzz = 1' and 'zzz = r + r2' are similar.  The former
> can have memory as the lhs (that includes static variables, or indirection
> through pointers), the latter can not.  The lhs of a binary statement is
> always an SSA name.  A write to an SSA name is not a store, which is why
> it's not walked for walk_stmt_load_store_addr_ops.
>
> Maybe it helps to look at simple C examples:
>
> % cat x.c
> int zzz;
> void foo(void) { zzz = 1; }
> void bar(int i) { zzz = i + 1; }
> % gcc -c x.c -fdump-tree-ssa-vops
> % cat x.c.*ssa
> foo ()
> {
>   <bb 2> :
>   # .MEM_2 = VDEF <.MEM_1(D)>
>   zzz = 1;
>   # VUSE <.MEM_2>
>   return;
> }
>
> bar (int i)
> {
>   int _1;
>
>   <bb 2> :
>   _1 = i_2(D) + 1;
>   # .MEM_4 = VDEF <.MEM_3(D)>
>   zzz = _1;
>   # VUSE <.MEM_4>
>   return;
>
> }
>
> See how the instruction writing to zzz (a global, and hence memory) is
> going through a temporary for the addition in bar?  This will always be
> the case when the expression is arithmetic.
>
> In SSA form gimple only very few instruction types can be stores, namely
> calls and stores like above (where the RHS is an unary tree).  If you want
> to capture writes into SSA names as well (which are more appropriately
> thought of as 'setting the ssa name' or 'associating the ssa name with the
> rhs value') you need the per-operand callback indeed.  But that depends on
> what you actually want to do.
>
>
> Ciao,
> Michael.

  parent reply	other threads:[~2021-03-17  7:42 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-15 18:31 Thomas Schwinge
2021-03-15 19:17 ` Richard Biener
2021-03-16 15:02   ` Thomas Schwinge
2021-03-16 15:16     ` Richard Biener
2021-03-16 15:25     ` Michael Matz
2021-03-16 23:24       ` Thomas Schwinge
2021-03-17  7:46         ` Richard Biener
2021-03-18 12:32           ` Thomas Schwinge
2021-03-17  7:42       ` Richard Biener [this message]
2021-03-17 13:27         ` Michael Matz

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=CAFiYyc2Eu1OhkPyZbxxuW-S-PtD5NESxJ1Fgm9DffsBCBf8+jA@mail.gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=gcc@gcc.gnu.org \
    --cc=matz@suse.de \
    --cc=thomas@codesourcery.com \
    /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).