From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2584E3858C2D; Tue, 11 Oct 2022 08:06:31 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2584E3858C2D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1665475591; bh=PKFjRY5FKAwNchCnQlpVZwZ7hf52+vIrkzbditBZbPI=; h=From:To:Subject:Date:From; b=DwUGIsOpMsgm3TJ36wwv54aQSAAKmbQdtCTYKKBMN+jHrMhkv1t5jux0M3c0O7rxF BXhUf09MqGuhwq7XqgSLGWRSXDEXbV8U++TaArV/dBrZJ0TjgYzyt5szNyEBMx87lH zi3/xqTjPJ7quSz53Ix/6OHOiHWeQZQjg6Iui0Cc= From: "aosman9xx9 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/107212] New: -O2 and -O3 optimizer bug Date: Tue, 11 Oct 2022 08:06:30 +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.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: aosman9xx9 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107212 Bug ID: 107212 Summary: -O2 and -O3 optimizer bug Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: aosman9xx9 at gmail dot com Target Milestone: --- There seams to be an optimizer bug in the recent gcc version. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D [root@archlinux ~]# gcc --version gcc (GCC) 12.2.0 (the current gcc version in Archlinux) [root@archlinux ~]# cat GccError.c #include int main() { unsigned int tab[6][2] =3D { {69, 73}, {36, 40}, {24, 16}, {16, 11}, {4= , 5}, {3, 1} }; int flag =3D 1; int sum_0 =3D 0; int sum_1 =3D 0; for(int t=3D0; t<6; t++) { sum_0 +=3D tab[t][0]; sum_1 +=3D tab[t][1]; } int x1 =3D (sum_0 < 100); int x2 =3D (sum_0 > 200); int x3 =3D (x1 || x2); if(sum_1 > 200) { flag=3D0; } printf("sum_0: %d\n", sum_0); printf("sum_1: %d\n", sum_1); printf("x1: %d\n", x1); printf("x2: %d\n", x2); printf("x1 || x2: %d\n", x3); printf("flag: %d\n", flag); return 0; } [root@archlinux ~]# gcc -O2 -Wall -Wextra -o GccError GccError.c [root@archlinux ~]# ./GccError sum_0: 152 sum_1: 146 x1: 0 x2: 0 x1 || x2: 1 flag: 1 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D The expected result of (x1 || x2) is 0, because x1 and x2 is 0. But the res= ult is 1. This only happens with -O2 or -O3 optimization.=