public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "sebastien.michelland@ens-lyon.fr" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/106609] New: [SH] miscompilation of loop involving noreturn call
Date: Sat, 13 Aug 2022 17:31:54 +0000	[thread overview]
Message-ID: <bug-106609-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 106609
           Summary: [SH] miscompilation of loop involving noreturn call
           Product: gcc
           Version: 12.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sebastien.michelland@ens-lyon.fr
  Target Milestone: ---

Created attachment 53452
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53452&action=edit
Minimal test case

GCC 12.1.0 generates incorrect code for loops that call into noreturn functions
starting at -O1. For example,

__attribute__((noreturn)) void g(void);
void f(int *values)
{
    for(int i = 0; i < 8; i++)
        if(values[i] != 0) g();
}

gets compiled into

        sts.l   pr,@-r15
        mov     #8,r1
.L3:    bt.s    .L2
        dt      r1
        mov.l   .L5,r1 # _g
        jsr     @r1
        nop
.L2:    bf      .L3
        lds.l   @r15+,pr
        rts     
        nop

which has the obvious issue of not reading its input, and also using the T bit
through bt.s before doing any test.

I suppose this is an overly aggressive loop/CFG optimization, but I was not
able to trim it down as unfolding -O1 into the list of optimizations provided
by -Q --help=optimizers produced a completely different program. The bug still
occurs with -fno-aggressive-loop-optimizations at least.

With -funroll-all-loops, instead of 8 mov.l/tst/bf I just get 8 bf which
suggests that the test is wrongly eliminated causing the load to become dead.

Found in:
  GCC 12.1.0
  Commit 4991e2092 of today's master
Not found in:
  GCC 11.1.0
Configured with:
  ../gcc-12.1.0/configure --prefix=$PREFIX --target=sh3eb-elf
--enable-languages=c --without-headers
Reproduction instructions:
  $PREFIX/bin/sh3eb-elf-gcc -S noreturn-loop-bug.c -o - -O1

             reply	other threads:[~2022-08-13 17:31 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-13 17:31 sebastien.michelland@ens-lyon.fr [this message]
2022-08-15  8:28 ` [Bug middle-end/106609] " rguenth at gcc dot gnu.org
2022-08-15  9:47 ` sebastien.michelland@ens-lyon.fr
2022-08-15 15:52 ` [Bug target/106609] " pinskia at gcc dot gnu.org
2022-08-16 21:03 ` [Bug target/106609] [SH] miscompilation due to incorrect elimination of comparisons to 0 sebastien.michelland@ens-lyon.fr
2022-08-16 21:03 ` sebastien.michelland@ens-lyon.fr
2022-08-17  8:09 ` sebastien.michelland@ens-lyon.fr
2022-11-24 13:13 ` [Bug target/106609] [12/13 Regression] sh3eb-elf cross compiler is being miscompiled since r12-1525-g3155d51bfd1de8b6c4645 jakub at gcc dot gnu.org
2022-11-24 14:38 ` [Bug target/106609] [12 " jakub at gcc dot gnu.org
2022-11-24 17:04 ` sebastien.michelland@ens-lyon.fr
2023-02-28 23:08 ` sam at gentoo dot org
2023-05-08 12:25 ` 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-106609-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).