public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/107212] New: -O2 and -O3 optimizer bug
@ 2022-10-11  8:06 aosman9xx9 at gmail dot com
  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
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: aosman9xx9 at gmail dot com @ 2022-10-11  8:06 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-01-24 15:23 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-11  8:06 [Bug c/107212] New: -O2 and -O3 optimizer bug aosman9xx9 at gmail dot com
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

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).