public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jwzeng at nuaa dot edu.cn" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/110410] New: [14 Regression] Different results between -O0 and -O2
Date: Mon, 26 Jun 2023 09:38:55 +0000	[thread overview]
Message-ID: <bug-110410-4@http.gcc.gnu.org/bugzilla/> (raw)

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

             reply	other threads:[~2023-06-26  9:38 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-26  9:38 jwzeng at nuaa dot edu.cn [this message]
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

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-110410-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: link
Be 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).