public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/109004] New: wrong code for -O2 (any above -O0) with g++ 11.3 for POWER9 (cross-compiler on x86_64 host)
@ 2023-03-03  9:59 bugreporter66 at gmail dot com
  2023-03-03 12:32 ` [Bug target/109004] [10/11/12/13 Regression] " rguenth at gcc dot gnu.org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: bugreporter66 at gmail dot com @ 2023-03-03  9:59 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 109004
           Summary: wrong code for -O2 (any above -O0) with g++ 11.3 for
                    POWER9 (cross-compiler on x86_64 host)
           Product: gcc
           Version: 11.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: bugreporter66 at gmail dot com
  Target Milestone: ---

Created attachment 54574
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54574&action=edit
archive with all the necessary source and output files

The code sample is attached with all the necessary output files. It's a
regression from g++ 9.x series, where it worked properly.

The line that fails the test is a ternary operator working on two memory
floating point operands: farr[n] < farr[m] ? farr[n] : farr[m];

Two potential workarounds for this are turning optimizations off (-O0) or
re-targeting to POWER8 instead (-O2 -mcpu=power8).

The test case is taken from https://github.com/VectorChief/UniSIMD-assembler,
where that test fails (v1.1.0c) for POWER9 target on Ubuntu MATE 22.04.2

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

* [Bug target/109004] [10/11/12/13 Regression] wrong code for -O2 (any above -O0) with g++ 11.3 for POWER9 (cross-compiler on x86_64 host)
  2023-03-03  9:59 [Bug target/109004] New: wrong code for -O2 (any above -O0) with g++ 11.3 for POWER9 (cross-compiler on x86_64 host) bugreporter66 at gmail dot com
@ 2023-03-03 12:32 ` rguenth at gcc dot gnu.org
  2023-03-04  6:42 ` bugreporter66 at gmail dot com
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-03-03 12:32 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |9.5.0
            Summary|wrong code for -O2 (any     |[10/11/12/13 Regression]
                   |above -O0) with g++ 11.3    |wrong code for -O2 (any
                   |for POWER9 (cross-compiler  |above -O0) with g++ 11.3
                   |on x86_64 host)             |for POWER9 (cross-compiler
                   |                            |on x86_64 host)
           Keywords|                            |wrong-code
   Target Milestone|---                         |10.5
             Target|                            |powerpc64le

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

* [Bug target/109004] [10/11/12/13 Regression] wrong code for -O2 (any above -O0) with g++ 11.3 for POWER9 (cross-compiler on x86_64 host)
  2023-03-03  9:59 [Bug target/109004] New: wrong code for -O2 (any above -O0) with g++ 11.3 for POWER9 (cross-compiler on x86_64 host) bugreporter66 at gmail dot com
  2023-03-03 12:32 ` [Bug target/109004] [10/11/12/13 Regression] " rguenth at gcc dot gnu.org
@ 2023-03-04  6:42 ` bugreporter66 at gmail dot com
  2023-03-15  8:43 ` jakub at gcc dot gnu.org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: bugreporter66 at gmail dot com @ 2023-03-04  6:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from bugreporter66 at gmail dot com ---
Checked g++ 10.4 today, it works as it should.
11.3 and 12.1 were tested to show the issue so far.

The command line for building:
powerpc64le-linux-gnu-g++ -O2 -static test.cpp -o test_p64

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

* [Bug target/109004] [10/11/12/13 Regression] wrong code for -O2 (any above -O0) with g++ 11.3 for POWER9 (cross-compiler on x86_64 host)
  2023-03-03  9:59 [Bug target/109004] New: wrong code for -O2 (any above -O0) with g++ 11.3 for POWER9 (cross-compiler on x86_64 host) bugreporter66 at gmail dot com
  2023-03-03 12:32 ` [Bug target/109004] [10/11/12/13 Regression] " rguenth at gcc dot gnu.org
  2023-03-04  6:42 ` bugreporter66 at gmail dot com
@ 2023-03-15  8:43 ` jakub at gcc dot gnu.org
  2023-03-16 10:40 ` bugreporter66 at gmail dot com
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-03-15  8:43 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
You haven't told what you think is a bug and what you think is correct
behavior.
I've tried to compile using 12.2.1 20221121
g++ -o test_p64-test{0,.ii} -mcpu=power9 -O0 -fpie -pie
g++ -o test_p64-test{2,.ii} -mcpu=power9 -O2 -fpie -pie
./test_p64-test0 > 0
./test_p64-test2 > 2
diff -up 0 2
g++ -o test_p64-test{0,.ii} -mcpu=power8 -O0 -fpie -pie
g++ -o test_p64-test{2,.ii} -fno-strict-aliasing -fwrapv
-fno-aggressive-loop-optimizations -mcpu=power9 -O2 -fpie -pie
./test_p64-test0 > 0
./test_p64-test2 > 2
diff -up 0 2
And neither shows any differences.
Attaching a screenshot is a very bad idea, one can't copy from it.  Only
preprocessed source should be attached, the rest should go in text here,
describe what to run and what is correct and what is wrong (best testcases just
abort if they don't behave as expected and exit with 0 otherwise).

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

* [Bug target/109004] [10/11/12/13 Regression] wrong code for -O2 (any above -O0) with g++ 11.3 for POWER9 (cross-compiler on x86_64 host)
  2023-03-03  9:59 [Bug target/109004] New: wrong code for -O2 (any above -O0) with g++ 11.3 for POWER9 (cross-compiler on x86_64 host) bugreporter66 at gmail dot com
                   ` (2 preceding siblings ...)
  2023-03-15  8:43 ` jakub at gcc dot gnu.org
@ 2023-03-16 10:40 ` bugreporter66 at gmail dot com
  2023-03-16 10:45 ` bugreporter66 at gmail dot com
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: bugreporter66 at gmail dot com @ 2023-03-16 10:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from bugreporter66 at gmail dot com ---
Created attachment 54680
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54680&action=edit
binaries and output files as text

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

* [Bug target/109004] [10/11/12/13 Regression] wrong code for -O2 (any above -O0) with g++ 11.3 for POWER9 (cross-compiler on x86_64 host)
  2023-03-03  9:59 [Bug target/109004] New: wrong code for -O2 (any above -O0) with g++ 11.3 for POWER9 (cross-compiler on x86_64 host) bugreporter66 at gmail dot com
                   ` (3 preceding siblings ...)
  2023-03-16 10:40 ` bugreporter66 at gmail dot com
@ 2023-03-16 10:45 ` bugreporter66 at gmail dot com
  2023-03-16 11:01 ` bugreporter66 at gmail dot com
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: bugreporter66 at gmail dot com @ 2023-03-16 10:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from bugreporter66 at gmail dot com ---
The test prints two array values (farr[11], farr[3]) and then calculates and
prints their respective minimum and maximum values. The first line
(unoptimized) is a correct behavior (only showing the first few lines of the
diff here).

ubuntu-mate@ubuntu-mate:~/Downloads/bug$ diff -up 0 2
--- 0   2023-03-16 10:20:33.592616511 +0000
+++ 2   2023-03-16 10:20:46.624839476 +0000
@@ -1,24 +1,24 @@
 farr[11] = 4.318749e+04, farr[3] = 1.468766e+00
-C MIN(farr[11],farr[3]) = 1.468766e+00, MAX(farr[11],farr[3]) = 4.318749e+04
+C MIN(farr[11],farr[3]) = 4.318749e+04, MAX(farr[11],farr[3]) = 4.318749e+04

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

* [Bug target/109004] [10/11/12/13 Regression] wrong code for -O2 (any above -O0) with g++ 11.3 for POWER9 (cross-compiler on x86_64 host)
  2023-03-03  9:59 [Bug target/109004] New: wrong code for -O2 (any above -O0) with g++ 11.3 for POWER9 (cross-compiler on x86_64 host) bugreporter66 at gmail dot com
                   ` (4 preceding siblings ...)
  2023-03-16 10:45 ` bugreporter66 at gmail dot com
@ 2023-03-16 11:01 ` bugreporter66 at gmail dot com
  2023-03-16 11:12 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: bugreporter66 at gmail dot com @ 2023-03-16 11:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from bugreporter66 at gmail dot com ---
The exact command line used to produce the new binaries (added -static):

ubuntu-mate@ubuntu-mate:~/Downloads/bug$ powerpc64le-linux-gnu-g++  -o
test_p64-test{0,.ii} -mcpu=power9 -O0 -fpie -pie -static
ubuntu-mate@ubuntu-mate:~/Downloads/bug$ 
ubuntu-mate@ubuntu-mate:~/Downloads/bug$ powerpc64le-linux-gnu-g++  -o
test_p64-test{2,.ii} -mcpu=power9 -O2 -fpie -pie -static

Also tried different QEMU versions (6.2.0, 5.1.0, 4.2.0) to eliminate the
possibility of emulation issue. The source and the compiler are the same as
with the original report.

ubuntu-mate@ubuntu-mate:~/Downloads/bug$ powerpc64le-linux-gnu-g++  --version
powerpc64le-linux-gnu-g++ (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0

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

* [Bug target/109004] [10/11/12/13 Regression] wrong code for -O2 (any above -O0) with g++ 11.3 for POWER9 (cross-compiler on x86_64 host)
  2023-03-03  9:59 [Bug target/109004] New: wrong code for -O2 (any above -O0) with g++ 11.3 for POWER9 (cross-compiler on x86_64 host) bugreporter66 at gmail dot com
                   ` (5 preceding siblings ...)
  2023-03-16 11:01 ` bugreporter66 at gmail dot com
@ 2023-03-16 11:12 ` jakub at gcc dot gnu.org
  2023-03-16 11:29 ` bugreporter66 at gmail dot com
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-03-16 11:12 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |WORKSFORME
             Status|UNCONFIRMED                 |RESOLVED

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Looks like qemu bug to me.  I get the exact same output even with your binaries
on native power9.

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

* [Bug target/109004] [10/11/12/13 Regression] wrong code for -O2 (any above -O0) with g++ 11.3 for POWER9 (cross-compiler on x86_64 host)
  2023-03-03  9:59 [Bug target/109004] New: wrong code for -O2 (any above -O0) with g++ 11.3 for POWER9 (cross-compiler on x86_64 host) bugreporter66 at gmail dot com
                   ` (6 preceding siblings ...)
  2023-03-16 11:12 ` jakub at gcc dot gnu.org
@ 2023-03-16 11:29 ` bugreporter66 at gmail dot com
  2023-03-16 11:49 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: bugreporter66 at gmail dot com @ 2023-03-16 11:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from bugreporter66 at gmail dot com ---
Good to know. I will file a QEMU bug then. Thank you for your efforts.

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

* [Bug target/109004] [10/11/12/13 Regression] wrong code for -O2 (any above -O0) with g++ 11.3 for POWER9 (cross-compiler on x86_64 host)
  2023-03-03  9:59 [Bug target/109004] New: wrong code for -O2 (any above -O0) with g++ 11.3 for POWER9 (cross-compiler on x86_64 host) bugreporter66 at gmail dot com
                   ` (7 preceding siblings ...)
  2023-03-16 11:29 ` bugreporter66 at gmail dot com
@ 2023-03-16 11:49 ` jakub at gcc dot gnu.org
  2023-03-16 12:47 ` bugreporter66 at gmail dot com
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2023-03-16 11:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
The program uses xsmincdp and xsmaxcdp instructions and it feels as if qemu
implements the latter exactly the same as the former.
So, I guess simpler testcase would be compile with -O2 -mcpu=power9 -ffast-math
__attribute__((noipa)) float
mymin (float x, float y)
{
  return __builtin_fminf (x, y);
}

__attribute__((noipa)) float
mymax (float x, float y)
{
  return __builtin_fmaxf (x, y);
}

int
main ()
{
  if (mymin (1.0f, 2.0f) != 1.0f)
    __builtin_abort ();
  if (mymax (1.0f, 2.0f) != 2.0f)
    __builtin_abort ();
}
and see if it aborts under qemu or not.

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

* [Bug target/109004] [10/11/12/13 Regression] wrong code for -O2 (any above -O0) with g++ 11.3 for POWER9 (cross-compiler on x86_64 host)
  2023-03-03  9:59 [Bug target/109004] New: wrong code for -O2 (any above -O0) with g++ 11.3 for POWER9 (cross-compiler on x86_64 host) bugreporter66 at gmail dot com
                   ` (8 preceding siblings ...)
  2023-03-16 11:49 ` jakub at gcc dot gnu.org
@ 2023-03-16 12:47 ` bugreporter66 at gmail dot com
  2023-03-16 12:48 ` bugreporter66 at gmail dot com
  2023-03-16 12:51 ` bugreporter66 at gmail dot com
  11 siblings, 0 replies; 13+ messages in thread
From: bugreporter66 at gmail dot com @ 2023-03-16 12:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from bugreporter66 at gmail dot com ---
Created attachment 54683
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54683&action=edit
sample_p64

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

* [Bug target/109004] [10/11/12/13 Regression] wrong code for -O2 (any above -O0) with g++ 11.3 for POWER9 (cross-compiler on x86_64 host)
  2023-03-03  9:59 [Bug target/109004] New: wrong code for -O2 (any above -O0) with g++ 11.3 for POWER9 (cross-compiler on x86_64 host) bugreporter66 at gmail dot com
                   ` (9 preceding siblings ...)
  2023-03-16 12:47 ` bugreporter66 at gmail dot com
@ 2023-03-16 12:48 ` bugreporter66 at gmail dot com
  2023-03-16 12:51 ` bugreporter66 at gmail dot com
  11 siblings, 0 replies; 13+ messages in thread
From: bugreporter66 at gmail dot com @ 2023-03-16 12:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from bugreporter66 at gmail dot com ---
I checked the simple version of the test with QEMU 6.2.0 and 7.0.0:

ubuntu-mate@ubuntu-mate:~/Downloads/test_p64$ 
ubuntu-mate@ubuntu-mate:~/Downloads/test_p64$ powerpc64le-linux-gnu-g++ -O2
-mcpu=power9 -ffast-math -static sample.cpp -o sample_p64
ubuntu-mate@ubuntu-mate:~/Downloads/test_p64$ 
ubuntu-mate@ubuntu-mate:~/Downloads/test_p64$ 
ubuntu-mate@ubuntu-mate:~/Downloads/test_p64$ qemu-ppc64le --version
qemu-ppc64le version 6.2.0
Copyright (c) 2003-2021 Fabrice Bellard and the QEMU Project developers
ubuntu-mate@ubuntu-mate:~/Downloads/test_p64$ 
ubuntu-mate@ubuntu-mate:~/Downloads/test_p64$ 
ubuntu-mate@ubuntu-mate:~/Downloads/test_p64$ qemu-ppc64le -cpu POWER9
sample_p64 
qemu: uncaught target signal 6 (Aborted) - core dumped
Aborted (core dumped)
ubuntu-mate@ubuntu-mate:~/Downloads/test_p64$ 
ubuntu-mate@ubuntu-mate:~/Downloads/test_p64$ 

...

ubuntu-mate@ubuntu-mate:~/Downloads/test_p64$ 
ubuntu-mate@ubuntu-mate:~/Downloads/test_p64$ 
ubuntu-mate@ubuntu-mate:~/Downloads/test_p64$ qemu-ppc64le --version
qemu-ppc64le version 7.0.0
Copyright (c) 2003-2022 Fabrice Bellard and the QEMU Project developers
ubuntu-mate@ubuntu-mate:~/Downloads/test_p64$ 
ubuntu-mate@ubuntu-mate:~/Downloads/test_p64$ 
ubuntu-mate@ubuntu-mate:~/Downloads/test_p64$ 
ubuntu-mate@ubuntu-mate:~/Downloads/test_p64$ qemu-ppc64le -cpu POWER9
sample_p64 
ubuntu-mate@ubuntu-mate:~/Downloads/test_p64$ 
ubuntu-mate@ubuntu-mate:~/Downloads/test_p64$ 

So it works after 7.0.0

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

* [Bug target/109004] [10/11/12/13 Regression] wrong code for -O2 (any above -O0) with g++ 11.3 for POWER9 (cross-compiler on x86_64 host)
  2023-03-03  9:59 [Bug target/109004] New: wrong code for -O2 (any above -O0) with g++ 11.3 for POWER9 (cross-compiler on x86_64 host) bugreporter66 at gmail dot com
                   ` (10 preceding siblings ...)
  2023-03-16 12:48 ` bugreporter66 at gmail dot com
@ 2023-03-16 12:51 ` bugreporter66 at gmail dot com
  11 siblings, 0 replies; 13+ messages in thread
From: bugreporter66 at gmail dot com @ 2023-03-16 12:51 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from bugreporter66 at gmail dot com ---
Created a QEMU bug here:
https://gitlab.com/qemu-project/qemu/-/issues/1547

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

end of thread, other threads:[~2023-03-16 12:51 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-03  9:59 [Bug target/109004] New: wrong code for -O2 (any above -O0) with g++ 11.3 for POWER9 (cross-compiler on x86_64 host) bugreporter66 at gmail dot com
2023-03-03 12:32 ` [Bug target/109004] [10/11/12/13 Regression] " rguenth at gcc dot gnu.org
2023-03-04  6:42 ` bugreporter66 at gmail dot com
2023-03-15  8:43 ` jakub at gcc dot gnu.org
2023-03-16 10:40 ` bugreporter66 at gmail dot com
2023-03-16 10:45 ` bugreporter66 at gmail dot com
2023-03-16 11:01 ` bugreporter66 at gmail dot com
2023-03-16 11:12 ` jakub at gcc dot gnu.org
2023-03-16 11:29 ` bugreporter66 at gmail dot com
2023-03-16 11:49 ` jakub at gcc dot gnu.org
2023-03-16 12:47 ` bugreporter66 at gmail dot com
2023-03-16 12:48 ` bugreporter66 at gmail dot com
2023-03-16 12:51 ` bugreporter66 at gmail dot com

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