From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 402CC3858404; Sat, 9 Oct 2021 17:03:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 402CC3858404 From: "davidsondfgl at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/102666] New: Wrong loop optimization for unsigned types Date: Sat, 09 Oct 2021 17:03:35 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 9.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: davidsondfgl at gmail dot com 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 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, 09 Oct 2021 17:03:35 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D102666 Bug ID: 102666 Summary: Wrong loop optimization for unsigned types Product: gcc Version: 9.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: davidsondfgl at gmail dot com Target Milestone: --- The code below produces incorrect result when any optimizations (-O1/-O2/-O= 3) are enabled: $ cat unsigned-bug.c int main(void) { for (unsigned a =3D 0, b =3D 0; a < 6; a +=3D 1, b +=3D 2) if (b < a) return 1; return 0; } $ gcc -Wall -Wextra unsigned-bug.c; ./a.out; echo $? 0 $ gcc -Wall -Wextra unsigned-bug.c -O1; ./a.out; echo $? 1 $ gcc -Wall -Wextra unsigned-bug.c -O2; ./a.out; echo $? 1 $ gcc -Wall -Wextra unsigned-bug.c -O3; ./a.out; echo $? 1 This affects all releases as of 9.1, including the master branch (commit 2b30143). A bisect between v9.1 and v8.3 indicates that this may have been introduced= in r266171, as I can revert this commit (a81e2c6) in all releases up to v11.2 = and get the expected behavior. It is also worthwhile to note that this only occurs for unsigned types.=