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 middle-end/100810] [12 Regression] wrong code at -O1 and above on x86_64-linux-gnu since r12-397-gda9e6e63d1ae22e530ec7baf59f6ed028bf05776
Date: Fri, 01 Apr 2022 11:06:21 +0000	[thread overview]
Message-ID: <bug-100810-4-rWKCj8ropE@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-100810-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
Btw, while in the abstract machine sense for the testcase 'i' is never actually
read the SSA GIMPLE already exposes an uninitialized read of it:

void k ()
{
...
  <bb 3> :
  a.9_3 = a;
  if (a.9_3 >= 0)
    goto <bb 5>; [INV]
  else
    goto <bb 15>; [INV]

  <bb 4> :
  i_25 = i_13 + 1;
  h.10_4 = h;
  _5 = h.10_4 + -1;
  h = _5;

  <bb 5> :
  # i_13 = PHI <i_20(D)(3), i_25(4)>
  a.11_6 = a;
  if (a.11_6 != 0)
    goto <bb 4>; [INV]
  else
    goto <bb 6>; [INV]

that's because for

  while (a) {
  }

which is not entered because 'a' is zero we have the PHI node for 'i' since
the condition is part of the loop and SSA form requires us to represent
the value of 'i' on the entry edge.

That means those uses are not real uses and thus do not invoke undefined
behavior (at the point of execution of the PHI node).  That would be
different from

  tem_2 = i_20(D);

<bbN>
  # tem_3 = PHI <tem_2, ..>

but copy propagation will turn this into the other case (but that would
be conservatively OK).


Note that for the testcase IVOPTs inserts the rewritten uses in a place
where i is now used unconditionally turning

  if (a.9_15 >= 0)
    goto <bb 20>; [59.00%]
  else
    goto <bb 15>; [41.00%]

  <bb 20> [local count: 139545903]:
  goto <bb 8>; [100.00%]

  <bb 7> [local count: 564526613]:
  i_17 = i_16 + 1;
  _19 = h_lsm.23_10 + -1;

  <bb 8> [local count: 634299566]:
  # i_16 = PHI <i_24(D)(20), i_17(7)>
  # h_lsm.23_10 = PHI <b.7_13(20), _19(7)>
  if (a.9_15 != 0)
    goto <bb 7>; [89.00%]
  else
    goto <bb 29>; [11.00%]

  <bb 29> [local count: 69772953]:

into

  if (a.9_15 >= 0)
    goto <bb 20>; [59.00%]
  else
    goto <bb 15>; [41.00%]

  <bb 20> [local count: 139545903]:
  goto <bb 8>; [100.00%]

  <bb 7> [local count: 564526613]:
  i_17 = i_16 + 1;

  <bb 8> [local count: 634299566]:
  # i_16 = PHI <i_24(D)(20), i_17(7)>
  _28 = (unsigned int) b.7_13;
  _41 = (unsigned int) i_24(D);
  _51 = _28 + _41;
  _22 = (unsigned int) i_16;
  _48 = -_22;
  _49 = _48 + _51;
  h_lsm.23_10 = (int) _49;
  if (a.9_15 != 0)
    goto <bb 7>; [89.00%]
  else
    goto <bb 29>; [11.00%]

  <bb 29> [local count: 69772953]:

when it eliminates the h_lsm.23 IV and rewrites it in terms of i.

  parent reply	other threads:[~2022-04-01 11:06 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-28  8:59 [Bug tree-optimization/100810] New: wrong code at -O1 and above on x86_64-linux-gnu zhendong.su at inf dot ethz.ch
2021-05-28  9:23 ` [Bug tree-optimization/100810] [12 Regression] wrong code at -O1 and above on x86_64-linux-gnu since r12-397-gda9e6e63d1ae22e530ec7baf59f6ed028bf05776 marxin at gcc dot gnu.org
2021-06-11  8:27 ` [Bug middle-end/100810] " roger at nextmovesoftware dot com
2021-06-14  9:37 ` jakub at gcc dot gnu.org
2021-08-03 21:21 ` roger at nextmovesoftware dot com
2021-08-03 21:36 ` pinskia at gcc dot gnu.org
2021-08-03 21:41 ` pinskia at gcc dot gnu.org
2021-08-03 21:47 ` pinskia at gcc dot gnu.org
2021-08-31  6:23 ` roger at nextmovesoftware dot com
2021-11-11 19:37 ` roger at nextmovesoftware dot com
2022-04-01 11:06 ` rguenth at gcc dot gnu.org [this message]
2022-04-01 11:08 ` rguenth at gcc dot gnu.org
2022-04-04 12:59 ` rguenth at gcc dot gnu.org
2022-04-04 13:00 ` rguenth at gcc dot gnu.org
2022-04-22  6:11 ` rguenth at gcc dot gnu.org
2022-04-25  7:52 ` cvs-commit at gcc dot gnu.org
2022-04-25  7:54 ` rguenth at gcc dot gnu.org
2022-06-03  7:05 ` cvs-commit at gcc dot gnu.org
2022-07-27  9:24 ` cvs-commit 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-100810-4-rWKCj8ropE@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).