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/97421] New: [10/11 Regression] aarch64: Wrong code with -O2 -fmodulo-sched since r10-1318-ga7e8a46
Date: Wed, 14 Oct 2020 13:58:34 +0000	[thread overview]
Message-ID: <bug-97421-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 97421
           Summary: [10/11 Regression] aarch64: Wrong code with -O2
                    -fmodulo-sched since r10-1318-ga7e8a46
           Product: gcc
           Version: 11.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: ---

AArch64 GCC miscompiles the following testcase:

int a, b, d, e;
int *volatile c = &a;

__attribute__((noinline))
void f(void)
{
  for (int g = 2; g >= 0; g--) {
    d = 0;
    for (b = 0; b <= 2; b++)
      ;
    e = *c;
  }
}

int main(void)
{
  f();
  if (b != 3)
    __builtin_abort();
}

with -O2 -fmodulo-sched since
r10-1318-ga7e8a463cd1dbaccf6e7c4fa888768fcd257a30f. Removing -fmodulo-sched,
the testcase is compiled correctly (tested at -O0 through -O3).

Here is the generated code (current trunk) for f at -O2:

f:
        mov     w1, 3
        adrp    x0, .LANCHOR0
        adrp    x3, .LANCHOR1
        mov     w4, w1
        add     x0, x0, :lo12:.LANCHOR0 // x0 <- &d
        add     x3, x3, :lo12:.LANCHOR1 // x3 <- &c
.L2:
        ldr     x2, [x3]      // x2 <- c
        stp     wzr, w4, [x0] // d = 0, b = 3
        subs    w1, w1, #1
        ldr     w2, [x2]      // w2 <- *c
        str     w2, [x0, 8]   // e <- w2
        bne     .L2
        ret

and the code for f with -O2 -fmodulo-sched:

f:
        mov     w1, 2
        adrp    x0, .LANCHOR0
        mov     w4, w1
        add     x0, x0, :lo12:.LANCHOR0
        adrp    x3, .LANCHOR1
        add     x3, x3, :lo12:.LANCHOR1
        ldr     x2, [x3]    // x2 <- c
        str     w1, [x0, 4] // b = 2
.L2:
        str     wzr, [x0]   // d = 0
        ldr     w2, [x2]    // w2 <- *c
        subs    w1, w1, #1  
        str     w2, [x0, 8] // e <- w2
        ldr     x2, [x3]    // x2 <- c
        str     w4, [x0, 4] // b = 2
        bne     .L2
        ldr     w2, [x2]    // w2 <- *c
        str     w2, [x0, 8] // e <- w2
        ret

In the latter case we end up with b = 2 and make the call to __builtin_abort().

             reply	other threads:[~2020-10-14 13:58 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-14 13:58 acoplan at gcc dot gnu.org [this message]
2020-10-14 14:00 ` [Bug tree-optimization/97421] " acoplan at gcc dot gnu.org
2020-10-14 14:09 ` [Bug rtl-optimization/97421] " rguenth at gcc dot gnu.org
2020-10-14 14:10 ` rguenth at gcc dot gnu.org
2020-10-14 14:27 ` acoplan at gcc dot gnu.org
2020-10-14 19:24 ` [Bug rtl-optimization/97421] aarch64: Wrong code with -O2 -fmodulo-sched acoplan at gcc dot gnu.org
2020-11-20 10:46 ` zhroma at gcc dot gnu.org
2020-11-20 10:54 ` zhroma at gcc dot gnu.org
2020-11-20 10:55 ` zhroma at gcc dot gnu.org
2020-11-20 11:07 ` zhroma at gcc dot gnu.org
2020-12-05 15:47 ` cvs-commit at gcc dot gnu.org
2020-12-24 16:41 ` cvs-commit at gcc dot gnu.org
2020-12-24 16:42 ` cvs-commit at gcc dot gnu.org
2020-12-24 16:44 ` cvs-commit at gcc dot gnu.org
2020-12-24 17:22 ` zhroma 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-97421-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).