public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/101501] [11/12 Regression] wrong code at -O3 on x86_64-linux-gnu
Date: Thu, 22 Jul 2021 08:07:45 +0000	[thread overview]
Message-ID: <bug-101501-4-zKHeQZF102@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-101501-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
    # of iterations (a_lsm.5_10 * 52) / 52, bounded by 63

is obviously wrong with a_lsm.5_10 being a 'char', that boils down to zero
iterations when computed at runtime.  The loop body looks like

  <bb 3> [local count: 1073741824]:
  # a_3 = PHI <a_5(2), a_6(5)>
d:
  a_6 = a_3 + 255;
  c_7 = a_3 * 52;
  if (c_7 != 0)
    goto <bb 5>; [89.00%]
  else
    goto <bb 4>; [11.00%]

  <bb 5> [local count: 955630224]:
  goto <bb 3>; [100.00%]

and SCEV computes

  (scalar = c_7)
  (scalar_evolution = {a_5 * 52, +, 204}_1))

which looks correct.

niter compute does

static bool
number_of_iterations_ne (class loop *loop, tree type, affine_iv *iv,
                         tree final, class tree_niter_desc *niter,
                         bool exit_must_be_taken, bounds *bnds)
{                       
...
  /* Compute no-overflow information for the control iv.  This can be
     proven when below two conditions are satisfied: 

       1) IV evaluates toward FINAL at beginning, i.e:
            base <= FINAL ; step > 0
            base >= FINAL ; step < 0

       2) |FINAL - base| is an exact multiple of step.
...
  if (!niter->control.no_overflow
      && (integer_onep (s) || multiple_of_p (type, c, s)))
    {

and there we have the issue of multiple_of_p not handling overflow (there's
a duplicate bug, PR100499 about this issue).  The 1) condition ends up
as unsigned-val >= 0 which is trivially true.

  parent reply	other threads:[~2021-07-22  8:07 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-18 22:50 [Bug tree-optimization/101501] New: " qrzhang at gatech dot edu
2021-07-18 22:51 ` [Bug tree-optimization/101501] " qrzhang at gatech dot edu
2021-07-18 23:01 ` [Bug tree-optimization/101501] [11/12 Regression] " pinskia at gcc dot gnu.org
2021-07-19  3:40 ` glisse at gcc dot gnu.org
2021-07-19  6:39 ` rguenth at gcc dot gnu.org
2021-07-22  7:19 ` rguenth at gcc dot gnu.org
2021-07-22  8:07 ` rguenth at gcc dot gnu.org [this message]
2021-07-22  8:09 ` rguenth 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-101501-4-zKHeQZF102@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).