public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Alexandre Oliva <oliva@adacore.com>
To: Richard Biener <richard.guenther@gmail.com>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>,
	Bin Cheng <bin.cheng@linux.alibaba.com>
Subject: Re: [PATCH] [PR105665] ivopts: check defs of names in base for undefs
Date: Wed, 01 Jun 2022 16:56:09 -0300	[thread overview]
Message-ID: <orczfs5fae.fsf@lxoliva.fsfla.org> (raw)
In-Reply-To: <CAFiYyc2nVx4n7XOPA-ZwB+k07n84j2z6Es08neGr+BRCsxsvTg@mail.gmail.com> (Richard Biener's message of "Wed, 1 Jun 2022 11:42:25 +0200")

On Jun  1, 2022, Richard Biener <richard.guenther@gmail.com> wrote:

> On Tue, May 31, 2022 at 3:27 PM Alexandre Oliva <oliva@adacore.com> wrote:
>    int i;
>    if (flag)
>      i = init;
>    i++;

> still would (the propagation stops at i++).

Uh, are you sure?  That doesn't sound right.  I meant for the
propagation to affect the incremented i as well, and any users thereof:
the incremented i is maybe-undefined, since its computation involves
another maybe-undefined value.

> do we understand the failure mode good enough to say that
> a must-def (even if from an SSA name without a definition) is good
> enough to avoid the issues we are seeing?

A must-def computed from a maybe-undef doesn't protect us from the
failure.  I assumed the failure mode was understood well enough to make
directly-visible undefined SSA_NAMEs problematic, and, given the finding
that indirectly-visible ones were also problematic, even with
multiple-steps removed, I figured other optimizations such as jump
threading could turn indirectly-visible undef names into
directly-visible ones, or that other passes could take advantage of
indirectly-visible undefinedness leading to potential undefined
behavior, to the point that we ought to avoid that.


> One would argue that my example above invokes undefined behavior
> if (!flag), but IIRC the cases in the PRs we talk about are not but
> IVOPTs with its IV choice exposes undefined behavior - orignially
> by relying on undef - undef being zero.

*nod*.  Perhaps we could refrain from propagating through assignments,
like the i++ increment above, rather than PHIs after the conditional
increment in my modified testcase, on the grounds that, if such non-PHI
assignments exercised, then we can assume any of its operands are
defined, because otherwise undefined behavior would have been invoked.

I.e., at least for ivopts purposes, we could propagate maybe-undefined
down PHI nodes only.

> That said, the contains-undef thing tries to avoid rewriting expressions
> with terms that possibly contain undefs which means if we want to
> strenthen it then we look for must-defined (currently it's must-undefined)?

I went for must-defined in the patch, but by computing its negated form,
maybe-undefined.  Now I'm thinking we can go for an even stricter
predicate to disable the optimization: if a non-PHI use of a
maybe-undefined dominates the loop, then we can still perform the
optimization:

>> >> +    int g;
>> >> +    if (f)
>> >> +      g++, b = 40;

           y = g+2;
           [loop]

The mere use of g before the loop requires it to be defined (even though
that's impossible above: either path carries the uninitialized value,
incremented or not), so we can proceed with the optimization under the
assumption that, after undefined behavior, anything goes.

This would be more useful for the case you showed, in which there's a
conditional initialization followed by an unconditional use.  The
requirement of no undefined behavior implies the conditional guarding
the initializer must hold, so the optimization can be performed.

WDYT?

-- 
Alexandre Oliva, happy hacker                https://FSFLA.org/blogs/lxo/
   Free Software Activist                       GNU Toolchain Engineer
Disinformation flourishes because many people care deeply about injustice
but very few check the facts.  Ask me about <https://stallmansupport.org>

  reply	other threads:[~2022-06-01 19:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-28  5:51 Alexandre Oliva
2022-05-30 12:21 ` Richard Biener
2022-05-31 13:27   ` Alexandre Oliva
2022-06-01  9:42     ` Richard Biener
2022-06-01 19:56       ` Alexandre Oliva [this message]
2022-06-02  7:10         ` Alexandre Oliva
2022-06-02  9:23           ` Richard Biener
2022-06-03  7:01             ` Alexandre Oliva

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=orczfs5fae.fsf@lxoliva.fsfla.org \
    --to=oliva@adacore.com \
    --cc=bin.cheng@linux.alibaba.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=richard.guenther@gmail.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).