public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/110532] New: [14 Regression] Different results between -O0 and -O1
@ 2023-07-03 11:17 jwzeng at nuaa dot edu.cn
  2023-07-03 11:31 ` [Bug tree-optimization/110532] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: jwzeng at nuaa dot edu.cn @ 2023-07-03 11:17 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110532
           Summary: [14 Regression] Different results between -O0 and -O1
           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: ---

Compiler Explorer: https://godbolt.org/z/xE1K6zKbs

The following code snippet:

#include <stdio.h>
unsigned char res, a[25], b[25];
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
int main() {
    for (int i = 0; i < 25; ++i)
        a[i] = 116, b[i] = 213;
    res = (unsigned char)min(b[0] ? (_Bool)-11818 : a[2], max(b[2], 1));
    printf("%d\n", res);
}

> $ /usr/gcc-trunk/bin/gcc -O0 bug.c; ./a.out
> 1
> $ /usr/gcc-trunk/bin/gcc -O1 bug.c; ./a.out
> 213
> $ /usr/gcc-trunk/bin/gcc -O2 bug.c; ./a.out
> 1
> $ /usr/gcc-trunk/bin/gcc -O3 bug.c; ./a.out
> 1
> $ /usr/gcc-trunk/bin/gcc -Os bug.c; ./a.out
> 1
When compiled with -O1, it prints the wrong result 213 instead of 1. Earlier
GCCs do not have this bug.

> $ /usr/gcc-trunk/bin/gcc --version
Using built-in specs.
COLLECT_GCC=/home/compilers/gcc/gcc-trunk/bin/gcc
COLLECT_LTO_WRAPPER=/home/compilers/gcc/gcc-trunk/bin/../libexec/gcc/x86_64-pc-linux-gnu/14.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc-trunk-source/gcc/configure
--enable-languages=c,c++,fortran --enable-checking=release
--enable-valgrind-annotations --disable-werror --disable-libstdcxx-pch
--enable-libgomp --enable-lto --enable-gold --with-plugin-ld=gold
--prefix=/usr/local/gcc-trunk
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 14.0.0 20230703 (experimental) [master r14-2244-g1ebf37ece3] (GCC)

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

* [Bug tree-optimization/110532] [14 Regression] Different results between -O0 and -O1
  2023-07-03 11:17 [Bug tree-optimization/110532] New: [14 Regression] Different results between -O0 and -O1 jwzeng at nuaa dot edu.cn
@ 2023-07-03 11:31 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-07-03 11:31 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
         Resolution|---                         |DUPLICATE
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
phiopt match-simplify trying:
        _3 > 1 ? 1 : _4
Matching expression match.pd:1991, gimple-match-5.cc:23
Matching expression match.pd:1991, gimple-match-5.cc:23
Applying pattern match.pd:4743, gimple-match-1.cc:16227
Folded into the sequence:
_12 = _3 > 1;
_19 = (unsigned char) _12;
_21 = _4 | _19;
statement un-sinked:
_4 = MAX_EXPR <_3, 1>;



  # RANGE [irange] unsigned char [1, 1] NONZERO 0x1
  _4 = MAX_EXPR <_3, 1>;

Funny this is also a missed optimization in dom3.

Dup of bug 110252 (the missed optmization is a dup of bug 110410)

*** This bug has been marked as a duplicate of bug 110252 ***

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

end of thread, other threads:[~2023-07-03 11:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-03 11:17 [Bug tree-optimization/110532] New: [14 Regression] Different results between -O0 and -O1 jwzeng at nuaa dot edu.cn
2023-07-03 11:31 ` [Bug tree-optimization/110532] " 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).