public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/104067] [12 Regression] wrong code compiling QEMU since r12-4790-g4b3a325f07acebf4
Date: Mon, 17 Jan 2022 16:16:41 +0000	[thread overview]
Message-ID: <bug-104067-4-5UqcpVn8Jw@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-104067-4@http.gcc.gnu.org/bugzilla/>

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |law at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
extern void abort ();
struct S { int x; } a[10];
struct S *b;

int
main ()
{
  int i, j = 0;
  struct S *q = a;

  for (i = 100; --i > 0; )
    {
      struct S *p;
      j++;
      if (j >= 10)
        j = 0;
      p = &a[j];

      if (p == q)
        abort ();
      __atomic_thread_fence (__ATOMIC_SEQ_CST);
      q = p;
    }
  return 0;
}

This goes wrong in threadfull2, strlen1 looks correct to me:
  <bb 2> [local count: 10737416]:

  <bb 3> [local count: 1063004409]:
  # j_17 = PHI <j_2(9), 0(2)>
  # q_18 = PHI <prephitmp_16(9), &a(2)>
  # ivtmp_4 = PHI <ivtmp_3(9), 99(2)>
  j_8 = j_17 + 1;
  if (j_8 == 10)
    goto <bb 5>; [34.00%]
  else
    goto <bb 4>; [66.00%]

  <bb 4> [local count: 701582906]:
  _1 = (sizetype) j_8;
  _15 = _1 * 4;
  _14 = &a + _15;

  <bb 5> [local count: 1063004409]:
  # j_2 = PHI <j_8(4), 0(3)>
  # prephitmp_16 = PHI <_14(4), &a(3)>
  if (prephitmp_16 == q_18)
    goto <bb 6>; [0.00%]
  else
    goto <bb 7>; [100.00%]

  <bb 6> [count: 0]:
  abort ();

  <bb 7> [local count: 1063004409]:
  __atomic_thread_fence (5);
  ivtmp_3 = ivtmp_4 - 1;
  if (ivtmp_3 != 0)
    goto <bb 9>; [99.00%]
  else
    goto <bb 8>; [1.00%]

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

  <bb 8> [local count: 10737416]:
  return 0;

but threadfull2 turns that into something that weirdly starts with:
  <bb 2> [local count: 10737416]:
  j_8 = 1;
  if (j_8 == 10)
    goto <bb 4>; [34.00%]
  else
    goto <bb 3>; [66.00%]

  <bb 3> [local count: 701582906]:
  # ivtmp_22 = PHI <99(2), ivtmp_12(7)>
  # j_24 = PHI <j_8(2), j_20(7)>
  # q_25 = PHI <&a(2), q_7(7)>
  _1 = (sizetype) j_24;
  _15 = _1 * 4;
  _14 = &a + _15;

  <bb 4> [local count: 705197120]:
  # j_2 = PHI <j_24(3), 0(2)>
  # prephitmp_16 = PHI <_14(3), &a(2)>
  # ivtmp_23 = PHI <ivtmp_22(3), 99(2)>
  # q_26 = PHI <q_25(3), &a(2)>
  if (prephitmp_16 == q_26)
    goto <bb 5>; [0.00%]
  else
    goto <bb 6>; [100.00%]

  <bb 5> [count: 0]:
  abort ();

and for j == 10 turns it into unconditional abort:
  j_20 = j_21 + 1;
  if (j_20 == 10)
    goto <bb 8>; [34.00%]
  else
    goto <bb 3>; [66.00%]

  <bb 8> [local count: 357807289]:
  # j_5 = PHI <0(7)>
  # prephitmp_9 = PHI <&a(7)>
  goto <bb 5>; [100.00%]

  parent reply	other threads:[~2022-01-17 16:16 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-17 14:00 [Bug middle-end/104067] New: wrong code compiling QEMU bonzini at gnu dot org
2022-01-17 14:08 ` [Bug middle-end/104067] [12 Regression] wrong code compiling QEMU since r12-4790-g4b3a325f07acebf4 marxin at gcc dot gnu.org
2022-01-17 14:09 ` marxin at gcc dot gnu.org
2022-01-17 15:50 ` jakub at gcc dot gnu.org
2022-01-17 16:16 ` jakub at gcc dot gnu.org [this message]
2022-01-17 18:04 ` amacleod at redhat dot com
2022-01-17 18:39 ` law at gcc dot gnu.org
2022-01-20 10:24 ` aldyh at gcc dot gnu.org
2022-01-20 13:28 ` aldyh 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-104067-4-5UqcpVn8Jw@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).