public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "aosman9xx9 at gmail dot com" <gcc-bugzilla@gcc.gnu.org> 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 [thread overview] Message-ID: <bug-107212-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107212 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. ================================= [root@archlinux ~]# gcc --version gcc (GCC) 12.2.0 (the current gcc version in Archlinux) [root@archlinux ~]# cat GccError.c #include <stdio.h> int main() { unsigned int tab[6][2] = { {69, 73}, {36, 40}, {24, 16}, {16, 11}, {4, 5}, {3, 1} }; int flag = 1; int sum_0 = 0; int sum_1 = 0; for(int t=0; t<6; t++) { sum_0 += tab[t][0]; sum_1 += tab[t][1]; } int x1 = (sum_0 < 100); int x2 = (sum_0 > 200); int x3 = (x1 || x2); if(sum_1 > 200) { flag=0; } 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 ================================= The expected result of (x1 || x2) is 0, because x1 and x2 is 0. But the result is 1. This only happens with -O2 or -O3 optimization.
next reply other threads:[~2022-10-11 8:06 UTC|newest] Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-10-11 8:06 aosman9xx9 at gmail dot com [this message] 2022-10-11 8:32 ` [Bug tree-optimization/107212] [11/12/13 Regression] Wrong vectorizer code since r11-718-gc735929a2503a7d0 marxin at gcc dot gnu.org 2022-10-11 8:42 ` rguenth at gcc dot gnu.org 2022-10-11 8:43 ` rguenth at gcc dot gnu.org 2022-10-11 8:44 ` marxin at gcc dot gnu.org 2022-10-11 9:30 ` rguenth at gcc dot gnu.org 2022-10-11 9:30 ` rguenth at gcc dot gnu.org 2022-10-11 11:15 ` cvs-commit at gcc dot gnu.org 2022-10-11 11:16 ` [Bug tree-optimization/107212] [11/12 " rguenth at gcc dot gnu.org 2022-10-17 13:10 ` cvs-commit at gcc dot gnu.org 2023-01-24 15:22 ` [Bug tree-optimization/107212] [11 " cvs-commit at gcc dot gnu.org 2023-01-24 15:23 ` 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-107212-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: linkBe 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).