public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/115766] New: [12/13/14 Regression] wrong code at optimization levels -O2, -O3
@ 2024-07-03  9:42 bic60176 at gmail dot com
  2024-07-03 10:21 ` [Bug tree-optimization/115766] " xry111 at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: bic60176 at gmail dot com @ 2024-07-03  9:42 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 115766
           Summary: [12/13/14 Regression] wrong code at optimization
                    levels -O2, -O3
           Product: gcc
           Version: 12.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bic60176 at gmail dot com
  Target Milestone: ---

Created attachment 58579
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58579&action=edit
testcase

OS: Ubuntu 22.04.3 LTS
We found that there are discrepancies when compiling with gcc-14.1.0,
gcc-13.2.0, gcc-12.3.0 at optimization levels -O2 and -O3.

$ ../compiler-builds/gcc-12.3.0_build/bin/gcc -fsanitize=undefined
-fsanitize=address -g -lgcc_s -I/home/csmith/include/csmith-2.3.0 -O2
testcase.c -o exec

$ timeout 1s ./exec 2>exec.err
checksum = 3BA9B585

$ ../compiler-builds/gcc-12.3.0_build/bin/gcc -fsanitize=undefined
-fsanitize=address -g -lgcc_s -I/home/csmith/include/csmith-2.3.0 -O0
testcase.c -o exec

$ timeout 1s ./exec 2>exec.err
checksum = 8861541D

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

* [Bug tree-optimization/115766] [12/13/14 Regression] wrong code at optimization levels -O2, -O3
  2024-07-03  9:42 [Bug tree-optimization/115766] New: [12/13/14 Regression] wrong code at optimization levels -O2, -O3 bic60176 at gmail dot com
@ 2024-07-03 10:21 ` xry111 at gcc dot gnu.org
  2024-07-03 10:28 ` bic60176 at gmail dot com
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: xry111 at gcc dot gnu.org @ 2024-07-03 10:21 UTC (permalink / raw)
  To: gcc-bugs

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

Xi Ruoyao <xry111 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |xry111 at gcc dot gnu.org

--- Comment #1 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
Please upload the *preprocessed* source (w/o csmith.h dependency).

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

* [Bug tree-optimization/115766] [12/13/14 Regression] wrong code at optimization levels -O2, -O3
  2024-07-03  9:42 [Bug tree-optimization/115766] New: [12/13/14 Regression] wrong code at optimization levels -O2, -O3 bic60176 at gmail dot com
  2024-07-03 10:21 ` [Bug tree-optimization/115766] " xry111 at gcc dot gnu.org
@ 2024-07-03 10:28 ` bic60176 at gmail dot com
  2024-07-03 12:28 ` rguenth at gcc dot gnu.org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: bic60176 at gmail dot com @ 2024-07-03 10:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Bi6c <bic60176 at gmail dot com> ---
Created attachment 58582
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58582&action=edit
preprocessed source file

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

* [Bug tree-optimization/115766] [12/13/14 Regression] wrong code at optimization levels -O2, -O3
  2024-07-03  9:42 [Bug tree-optimization/115766] New: [12/13/14 Regression] wrong code at optimization levels -O2, -O3 bic60176 at gmail dot com
  2024-07-03 10:21 ` [Bug tree-optimization/115766] " xry111 at gcc dot gnu.org
  2024-07-03 10:28 ` bic60176 at gmail dot com
@ 2024-07-03 12:28 ` rguenth at gcc dot gnu.org
  2024-07-15  8:18 ` bic60176 at gmail dot com
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-07-03 12:28 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |needs-bisection,
                   |                            |needs-reduction, wrong-code
   Target Milestone|---                         |12.5

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

* [Bug tree-optimization/115766] [12/13/14 Regression] wrong code at optimization levels -O2, -O3
  2024-07-03  9:42 [Bug tree-optimization/115766] New: [12/13/14 Regression] wrong code at optimization levels -O2, -O3 bic60176 at gmail dot com
                   ` (2 preceding siblings ...)
  2024-07-03 12:28 ` rguenth at gcc dot gnu.org
@ 2024-07-15  8:18 ` bic60176 at gmail dot com
  2024-07-15  8:20 ` bic60176 at gmail dot com
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: bic60176 at gmail dot com @ 2024-07-15  8:18 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Bi6c <bic60176 at gmail dot com> ---
Created attachment 58664
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58664&action=edit
reduced testcase

I reduced the testcase and removed the csmith dependency.

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

* [Bug tree-optimization/115766] [12/13/14 Regression] wrong code at optimization levels -O2, -O3
  2024-07-03  9:42 [Bug tree-optimization/115766] New: [12/13/14 Regression] wrong code at optimization levels -O2, -O3 bic60176 at gmail dot com
                   ` (3 preceding siblings ...)
  2024-07-15  8:18 ` bic60176 at gmail dot com
@ 2024-07-15  8:20 ` bic60176 at gmail dot com
  2024-07-15  8:20 ` bic60176 at gmail dot com
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: bic60176 at gmail dot com @ 2024-07-15  8:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Bi6c <bic60176 at gmail dot com> ---
Created attachment 58665
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58665&action=edit
preprocessed file w/o csmith.h dependency

Preprocessed file w/o csmith.h dependency

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

* [Bug tree-optimization/115766] [12/13/14 Regression] wrong code at optimization levels -O2, -O3
  2024-07-03  9:42 [Bug tree-optimization/115766] New: [12/13/14 Regression] wrong code at optimization levels -O2, -O3 bic60176 at gmail dot com
                   ` (4 preceding siblings ...)
  2024-07-15  8:20 ` bic60176 at gmail dot com
@ 2024-07-15  8:20 ` bic60176 at gmail dot com
  2024-07-17  4:06 ` sjames at gcc dot gnu.org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: bic60176 at gmail dot com @ 2024-07-15  8:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Bi6c <bic60176 at gmail dot com> ---
The discrepancy also appeared when compiling with optimization level -Os

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

* [Bug tree-optimization/115766] [12/13/14 Regression] wrong code at optimization levels -O2, -O3
  2024-07-03  9:42 [Bug tree-optimization/115766] New: [12/13/14 Regression] wrong code at optimization levels -O2, -O3 bic60176 at gmail dot com
                   ` (5 preceding siblings ...)
  2024-07-15  8:20 ` bic60176 at gmail dot com
@ 2024-07-17  4:06 ` sjames at gcc dot gnu.org
  2024-07-17  6:49 ` bic60176 at gmail dot com
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: sjames at gcc dot gnu.org @ 2024-07-17  4:06 UTC (permalink / raw)
  To: gcc-bugs

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

Sam James <sjames at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |needs-reduction

--- Comment #6 from Sam James <sjames at gcc dot gnu.org> ---
(In reply to Bi6c from comment #4)
> Created attachment 58665 [details]
> preprocessed file w/o csmith.h dependency
> 
> Preprocessed file w/o csmith.h dependency

k uses 'l' uninitialised.

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

* [Bug tree-optimization/115766] [12/13/14 Regression] wrong code at optimization levels -O2, -O3
  2024-07-03  9:42 [Bug tree-optimization/115766] New: [12/13/14 Regression] wrong code at optimization levels -O2, -O3 bic60176 at gmail dot com
                   ` (6 preceding siblings ...)
  2024-07-17  4:06 ` sjames at gcc dot gnu.org
@ 2024-07-17  6:49 ` bic60176 at gmail dot com
  2024-07-17  7:09 ` sjames at gcc dot gnu.org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: bic60176 at gmail dot com @ 2024-07-17  6:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Bi6c <bic60176 at gmail dot com> ---
(In reply to Sam James from comment #6)
> (In reply to Bi6c from comment #4)
> > Created attachment 58665 [details]
> > preprocessed file w/o csmith.h dependency
> > 
> > Preprocessed file w/o csmith.h dependency
> 
> k uses 'l' uninitialised.

the value of l is used as argument m in h(), and the argument m is initialized
in the for loop.
I initialized l by change the line 71 to "int64_t l=1;", and the discrepancies
still exist.

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

* [Bug tree-optimization/115766] [12/13/14 Regression] wrong code at optimization levels -O2, -O3
  2024-07-03  9:42 [Bug tree-optimization/115766] New: [12/13/14 Regression] wrong code at optimization levels -O2, -O3 bic60176 at gmail dot com
                   ` (7 preceding siblings ...)
  2024-07-17  6:49 ` bic60176 at gmail dot com
@ 2024-07-17  7:09 ` sjames at gcc dot gnu.org
  2024-07-18  6:59 ` bic60176 at gmail dot com
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: sjames at gcc dot gnu.org @ 2024-07-17  7:09 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Sam James <sjames at gcc dot gnu.org> ---
Are you sure the reduced one is accurate? For me, it behaves the same with
-O0..-O3 for GCC. For Clang, it has the same behaviour as GCC with -O0, and
"passes" with > -O0.

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

* [Bug tree-optimization/115766] [12/13/14 Regression] wrong code at optimization levels -O2, -O3
  2024-07-03  9:42 [Bug tree-optimization/115766] New: [12/13/14 Regression] wrong code at optimization levels -O2, -O3 bic60176 at gmail dot com
                   ` (8 preceding siblings ...)
  2024-07-17  7:09 ` sjames at gcc dot gnu.org
@ 2024-07-18  6:59 ` bic60176 at gmail dot com
  2024-07-18  7:03 ` bic60176 at gmail dot com
  2024-07-19 15:03 ` [Bug tree-optimization/115766] [12/13/14/15 " jakub at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: bic60176 at gmail dot com @ 2024-07-18  6:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from Bi6c <bic60176 at gmail dot com> ---
https://godbolt.org/

Yes, I also tried to use the compiler explorer. When I compiled with
gcc-12.3.0, I got the results below.
-O0: c[7][4].a: 2
-O2: c[7][4].a: 3

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

* [Bug tree-optimization/115766] [12/13/14 Regression] wrong code at optimization levels -O2, -O3
  2024-07-03  9:42 [Bug tree-optimization/115766] New: [12/13/14 Regression] wrong code at optimization levels -O2, -O3 bic60176 at gmail dot com
                   ` (9 preceding siblings ...)
  2024-07-18  6:59 ` bic60176 at gmail dot com
@ 2024-07-18  7:03 ` bic60176 at gmail dot com
  2024-07-19 15:03 ` [Bug tree-optimization/115766] [12/13/14/15 " jakub at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: bic60176 at gmail dot com @ 2024-07-18  7:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from Bi6c <bic60176 at gmail dot com> ---
Sorry I pasted the wrong link.
It should be this one https://godbolt.org/z/GM13fhWbb

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

* [Bug tree-optimization/115766] [12/13/14/15 Regression] wrong code at optimization levels -O2, -O3
  2024-07-03  9:42 [Bug tree-optimization/115766] New: [12/13/14 Regression] wrong code at optimization levels -O2, -O3 bic60176 at gmail dot com
                   ` (10 preceding siblings ...)
  2024-07-18  7:03 ` bic60176 at gmail dot com
@ 2024-07-19 15:03 ` jakub at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2024-07-19 15:03 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |jakub at gcc dot gnu.org
         Resolution|---                         |INVALID

--- Comment #11 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The testcase is bogus.
As documented, you can't really take address of the different union members and
access interchangeably through such pointers.
In standard C/C++, only one union element is active, access to all the others
while another one is active are UB (unless you assign to a different one and
through that activate it).  So, union type punning is not valid in standard
C/C++ at all.
GCC as an extension allows type punning through unions, but only if the union
is visible in the access path.
See https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#Type-punning

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

end of thread, other threads:[~2024-07-19 15:03 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-03  9:42 [Bug tree-optimization/115766] New: [12/13/14 Regression] wrong code at optimization levels -O2, -O3 bic60176 at gmail dot com
2024-07-03 10:21 ` [Bug tree-optimization/115766] " xry111 at gcc dot gnu.org
2024-07-03 10:28 ` bic60176 at gmail dot com
2024-07-03 12:28 ` rguenth at gcc dot gnu.org
2024-07-15  8:18 ` bic60176 at gmail dot com
2024-07-15  8:20 ` bic60176 at gmail dot com
2024-07-15  8:20 ` bic60176 at gmail dot com
2024-07-17  4:06 ` sjames at gcc dot gnu.org
2024-07-17  6:49 ` bic60176 at gmail dot com
2024-07-17  7:09 ` sjames at gcc dot gnu.org
2024-07-18  6:59 ` bic60176 at gmail dot com
2024-07-18  7:03 ` bic60176 at gmail dot com
2024-07-19 15:03 ` [Bug tree-optimization/115766] [12/13/14/15 " jakub 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).