public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "amacleod at redhat dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/99966] Bounds check not eliminated by assert
Date: Tue, 11 Jan 2022 18:59:33 +0000	[thread overview]
Message-ID: <bug-99966-4-2zvytVquVQ@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-99966-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99966

Andrew Macleod <amacleod at redhat dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |amacleod at redhat dot com

--- Comment #2 from Andrew Macleod <amacleod at redhat dot com> ---
looking at VRP2:
the initial assert provides:

Relational : (start_4(D) < end_5(D))
Relational : (_16 > start_4(D))
Relational : (end_5(D) <= _16)


unfortunately, the loop back edge is:
    i_12 = i_17 + 1;
    if (end_5(D) != i_12)
      goto <bb 5>; [89.00%]
    else
      goto <bb 8>; [11.00%]

so it only registers what it knows from the branch:
Relational : (i_12 != end_5(D))

so when it gets to the bounds check at:
    if (i_12 >= _16)
      goto <bb 6>; [0.04%]
    else
      goto <bb 10>; [99.96%]

It doesn't really know the answer.  If the loop branch had remained
if (i_12 < end_5) instead of being changed, then we would instead get the
relation:
Relational : (i_12 < end_5(D))
which combined with the earlier Relational : (end_5(D) <= _16), should register
 the transitive relation (i_12 < _16), and enable removal of the check.

This is transformed in ivopts, which runs after vrp1.  A quick check shows at
VRP1 time, the bounds are still using the < format...

In fact...  running with --param=vrp1-mode=ranger registers this exact
transitive relation, and produces:

Relational : (i_2 < _16)
Relational : (i_2 < end_5(D))
    <bb 6> [local count: 952547451]:
    if (0 != 0)
      goto <bb 7>; [0.04%]
    else
      goto <bb 8>; [99.96%]

and eliminates the bounds check.

So we can close this PR when we turn ranger on by default for VRP1.

  parent reply	other threads:[~2022-01-11 18:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-08  1:23 [Bug tree-optimization/99966] New: " jmuizelaar at mozilla dot com
2021-04-08  7:19 ` [Bug tree-optimization/99966] " rguenth at gcc dot gnu.org
2022-01-11 18:59 ` amacleod at redhat dot com [this message]
2022-11-03 19:31 ` amacleod at redhat dot com
2022-11-28 22:09 ` pinskia at gcc dot gnu.org

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=bug-99966-4-2zvytVquVQ@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).