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/110515] [12/13/14 Regression] llvm-15.0.7 possibly invalid code on -O3
Date: Wed, 05 Jul 2023 12:36:27 +0000	[thread overview]
Message-ID: <bug-110515-4-zrJAVFeiaQ@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-110515-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
So IMHO it's the fault of invariant motion moving

_145 = MEM[(struct LargeRep *)&Visited + 8B].Slots;

and

_34 = MEM[(struct LargeRep *)&Visited + 8B].Capacity;

out of loop 10 as these loads are executed conditional.  They are know
to not trap and that's why LIM doesn't require them unconditionally
executed but as we can see here CSE later takes advantage of undefinedness
if there's a load using the wrong TBAA type not matching the dynamic type
of the storage.

For example

char storage[4] __attribute__((aligned(4)));
double foo (int n, int kind)
{
  double res;
  for (int i = 0; i < n; ++i)
    if (kind)
      res = *(int *)storage;
    else
      res = *(float *)storage;
  return res;
}

is transformed to

  <bb 2> [local count: 118111600]:
  if (n_7(D) > 0)
    goto <bb 8>; [89.00%]
  else
    goto <bb 7>; [11.00%]

  <bb 8> [local count: 105119324]:
  _2 = MEM[(float *)&storage];
  _1 = MEM[(int *)&storage];

  <bb 3> [local count: 955630225]:
  # i_16 = PHI <i_13(9), 0(8)>
  if (kind_10(D) != 0)
    goto <bb 4>; [50.00%]
  else
    goto <bb 5>; [50.00%]

  <bb 4> [local count: 477815112]:
  res_12 = (double) _1;
  goto <bb 6>; [100.00%]

  <bb 5> [local count: 477815112]:
  res_11 = (double) _2;

  <bb 6> [local count: 955630225]:
  # res_3 = PHI <res_12(4), res_11(5)>
  i_13 = i_16 + 1;
  if (n_7(D) > i_13)
    goto <bb 9>; [89.00%]
  else
    goto <bb 7>; [11.00%]

  <bb 9> [local count: 850510901]:
  goto <bb 3>; [100.00%]

  <bb 7> [local count: 118111600]:
  # res_15 = PHI <res_3(6), res_6(D)(2)>
  return res_15;

and then eventually to the following, unconditionally using float as alias set.

  <bb 2> [local count: 118111600]:
  if (n_7(D) > 0)
    goto <bb 3>; [89.00%]
  else
    goto <bb 6>; [11.00%]

  <bb 3> [local count: 105119324]:
  _2 = MEM[(float *)&storage];
  if (kind_10(D) != 0)
    goto <bb 4>; [50.00%]
  else
    goto <bb 5>; [50.00%]

  <bb 4> [local count: 52559662]:
  _4 = VIEW_CONVERT_EXPR<int>(_2);
  res_12 = (double) _4;
  goto <bb 6>; [100.00%]

  <bb 5> [local count: 52559662]:
  res_11 = (double) _2;

  <bb 6> [local count: 118111600]:
  # res_15 = PHI <res_11(5), res_6(D)(2), res_12(4)>
  return res_15;

  parent reply	other threads:[~2023-07-05 12:36 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-01 21:52 [Bug middle-end/110515] New: [14 " slyfox at gcc dot gnu.org
2023-07-01 21:56 ` [Bug middle-end/110515] " slyfox at gcc dot gnu.org
2023-07-01 22:11 ` pinskia at gcc dot gnu.org
2023-07-01 22:12 ` [Bug middle-end/110515] " pinskia at gcc dot gnu.org
2023-07-01 22:12 ` [Bug middle-end/110515] [12/13/14 Regression] " pinskia at gcc dot gnu.org
2023-07-01 22:37 ` pinskia at gcc dot gnu.org
2023-07-01 23:32 ` pinskia at gcc dot gnu.org
2023-07-03  7:12 ` rguenth at gcc dot gnu.org
2023-07-04 22:40 ` slyfox at gcc dot gnu.org
2023-07-05 10:57 ` rguenth at gcc dot gnu.org
2023-07-05 12:36 ` rguenth at gcc dot gnu.org [this message]
2023-07-05 13:55 ` rguenth at gcc dot gnu.org
2023-07-06  7:30 ` cvs-commit at gcc dot gnu.org
2023-07-06  7:30 ` [Bug middle-end/110515] [12/13 " rguenth at gcc dot gnu.org
2023-07-06 10:09 ` slyfox at gcc dot gnu.org
2023-07-07 12:07 ` [Bug middle-end/110515] [12 " cvs-commit at gcc dot gnu.org
2023-11-27 11:34 ` cvs-commit at gcc dot gnu.org
2023-11-27 11:38 ` 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-110515-4-zrJAVFeiaQ@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).