From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9C8893858CDB; Sat, 13 Aug 2022 17:31:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9C8893858CDB From: "sebastien.michelland@ens-lyon.fr" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 12.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: sebastien.michelland@ens-lyon.fr X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 13 Aug 2022 17:31:54 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D106609 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=3D53452&action=3Dedit Minimal test case GCC 12.1.0 generates incorrect code for loops that call into noreturn funct= ions starting at -O1. For example, __attribute__((noreturn)) void g(void); void f(int *values) { for(int i =3D 0; i < 8; i++) if(values[i] !=3D 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=20=20=20=20=20 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 provid= ed by -Q --help=3Doptimizers 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 dea= d. 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=3D$PREFIX --target=3Dsh3eb-elf --enable-languages=3Dc --without-headers Reproduction instructions: $PREFIX/bin/sh3eb-elf-gcc -S noreturn-loop-bug.c -o - -O1=