public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/110410] New: [14 Regression] Different results between -O0 and -O2
@ 2023-06-26  9:38 jwzeng at nuaa dot edu.cn
  2023-06-26 10:11 ` [Bug tree-optimization/110410] " jwzeng at nuaa dot edu.cn
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: jwzeng at nuaa dot edu.cn @ 2023-06-26  9:38 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110410

            Bug ID: 110410
           Summary: [14 Regression] Different results between -O0 and -O2
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jwzeng at nuaa dot edu.cn
  Target Milestone: ---

The following code snippet:

#include <stdio.h>
int seed;
void hash(int *seed, int v) { *seed ^= v; }
unsigned int var_6 = 1341494070U;
int var_7 = 0;
unsigned short var_8 = 7472;
int var_13 = 518868156U;
unsigned var_17;
#define min(a, b) ((a) < (b) ? (a) : (b))
void test() {
    for (int ii_0 = 0; ii_0 < 20; ++ii_0)
        for (int ii_1 = 0; ii_1 < 10; ++ii_1)
            var_17 = min(var_6 ? var_8 >> (var_13 - 518868145U) : var_7,
1887837879 || 0);
}
int main() {
    test(2062689408U);
    hash(&seed, var_17);
    printf("%d\n", seed);
    return 0;
}

> $ /usr/gcc-trunk/bin/gcc -O0 bug.c; ./a.out
> 1
> $ /usr/gcc-trunk/bin/gcc -O2 bug.c; ./a.out
> 3

When compiled with -O2 or -O3, it prints 3 instead of 1. Earlier GCCs do not
have this bug.

> $ /usr/gcc-trunk/bin/gcc --version
gcc (GCC) 14.0.0 20230619 (experimental) [master r14-1917-gf8e0270272]
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE

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

end of thread, other threads:[~2023-07-19 16:36 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-26  9:38 [Bug tree-optimization/110410] New: [14 Regression] Different results between -O0 and -O2 jwzeng at nuaa dot edu.cn
2023-06-26 10:11 ` [Bug tree-optimization/110410] " jwzeng at nuaa dot edu.cn
2023-06-26 11:37 ` rguenth at gcc dot gnu.org
2023-06-26 12:32 ` jwzeng at nuaa dot edu.cn
2023-06-26 15:58 ` pinskia at gcc dot gnu.org
2023-06-26 16:07 ` pinskia at gcc dot gnu.org
2023-06-26 21:32 ` pinskia at gcc dot gnu.org
2023-07-19 16:19 ` pinskia at gcc dot gnu.org
2023-07-19 16:36 ` [Bug tree-optimization/110410] Missed optimization in DOM with a single value range pinskia 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).