public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "acoplan at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/113787] New: [14 Regression] Wrong code at -O with ipa-modref on aarch64
Date: Tue, 06 Feb 2024 13:40:46 +0000	[thread overview]
Message-ID: <bug-113787-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 113787
           Summary: [14 Regression] Wrong code at -O with ipa-modref on
                    aarch64
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: acoplan at gcc dot gnu.org
  Target Milestone: ---

The following testcase appears to be miscompiled on the trunk, on
aarch64-linux-gnu:

$ cat t.c
void foo(int x, int y, int z, int d, int *buf)
{
  for(int i = z; i < y-z; ++i)
    for(int j = 0; j < d; ++j)
      /* buf[x(i+1) + j] = buf[x(i+1)-j-1] */
      buf[i*x+(x-z+j)] = buf[i*x+(x-z-1-j)];
}

void bar(int x, int y, int z, int d, int *buf)
{
  for(int i = 0; i < d; ++i)
    for(int j = z; j < x-z; ++j)
      /* buf[j+(y+i)*x] = buf[j+(y-1-i)*x] */
      buf[j+(y-z+i)*x] = buf[j+(y-z-1-i)*x];
}

__attribute__((noipa))
void baz(int x, int y, int d, int *buf)
{
  foo(x, y, 0, d, buf);
  bar(x, y, 0, d, buf);
}

int main(void)
{
  int a[] = { 1, 2, 3 };
  baz (1, 2, 1, a);
  /* foo does:
     buf[1] = buf[0];
     buf[2] = buf[1];

     bar does:
     buf[2] = buf[1]; (no-op)
     so we should have { 1, 1, 1 }.  */
  for (int i = 0; i < 3; i++)
    if (a[i] != 1)
      __builtin_abort ();
}
$ gcc t.c -O -fno-ipa-modref
$ ./a.out
$ gcc t.c -O
$ ./a.out
Aborted

The problem seems to be that the call to foo gets incorrectly optimized
out from baz when ipa-modref is enabled:

$ gcc -c -S -o /dev/null t.c -O -fno-ipa-modref -fdump-tree-optimized=good.tree
$ gcc -c -S -o /dev/null t.c -O -fdump-tree-optimized=bad.tree
$ diff -u good.tree bad.tree
--- good.tree   2024-02-06 13:23:36.080926703 +0000
+++ bad.tree    2024-02-06 13:23:38.356916302 +0000
@@ -223,7 +223,6 @@
 void baz (int x, int y, int d, int * buf)
 {
   <bb 2> [local count: 1073741824]:
-  foo (x_2(D), y_3(D), 0, d_4(D), buf_5(D));
   bar (x_2(D), y_3(D), 0, d_4(D), buf_5(D));
   return;

I can't seem to reproduce the issue with GCC 13 or on x86_64.

             reply	other threads:[~2024-02-06 13:40 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-06 13:40 acoplan at gcc dot gnu.org [this message]
2024-02-06 13:49 ` [Bug tree-optimization/113787] " jakub at gcc dot gnu.org
2024-02-06 13:56 ` pinskia at gcc dot gnu.org
2024-02-06 13:57 ` acoplan at gcc dot gnu.org
2024-02-06 14:07 ` acoplan at gcc dot gnu.org
2024-02-06 14:13 ` [Bug tree-optimization/113787] [12/13/14 " jakub at gcc dot gnu.org
2024-02-06 14:19 ` pinskia at gcc dot gnu.org
2024-02-06 14:23 ` acoplan at gcc dot gnu.org
2024-02-06 15:41 ` hubicka at gcc dot gnu.org
2024-02-06 16:18 ` pinskia at gcc dot gnu.org
2024-02-07  8:48 ` rguenth at gcc dot gnu.org
2024-02-07  8:49 ` rguenth at gcc dot gnu.org
2024-02-08 14:40 ` acoplan at gcc dot gnu.org
2024-02-13  9:03 ` hubicka at gcc dot gnu.org
2024-02-13  9:21 ` rguenther at suse dot de
2024-02-13 18:21 ` hubicka at ucw dot cz
2024-02-14  8:19 ` rguenther at suse dot de
2024-02-14 15:07   ` Jan Hubicka
2024-02-14 15:07 ` hubicka at ucw dot cz
2024-02-14 15:09 ` rguenther at suse dot de
2024-02-14 15:18 ` hubicka at ucw dot cz
2024-05-16  9:07 ` [Bug tree-optimization/113787] [12/13/14/15 " acoplan at gcc dot gnu.org
2024-05-16 13:34 ` cvs-commit at gcc dot gnu.org
2024-05-16 13:39 ` [Bug tree-optimization/113787] [12/13/14 " hubicka 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-113787-4@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).