public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug translation/94500] New: Wrong maximum value with small integer types and AVX-512
@ 2020-04-06 13:08 ben at rockshrub dot de
  2020-04-06 13:09 ` [Bug translation/94500] " ben at rockshrub dot de
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: ben at rockshrub dot de @ 2020-04-06 13:08 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 94500
           Summary: Wrong maximum value with small integer types and
                    AVX-512
           Product: gcc
           Version: 8.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: translation
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ben at rockshrub dot de
  Target Milestone: ---

Created attachment 48211
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48211&action=edit
C++ program that triggers the bug

Both g++ and gfortran produce incorrect code for computing maximum values of
arrays of integer types smaller than 32 bit when optimizing for usage of
AVX-512. This can be triggered by using std::max_element in C++ or Fortran's
maxval.

The generated program uses 32-bit shuffles to reduce a 512-bit vector into a
final 8-bit or 16-bit result (set smallint to int8_t or int16_t), so if the
true maximum value never ends up in the least significant bytes of one of the
32-bit elements in the vector, it is never found.

The issue persists on GCC 8.4.0, but seems to be fixed on 9.X versions of GCC.

The attached program fills a vector in a way that triggers the error and then
computes the maximum value once "by hand" and once using std::max_element. It
prints the results of the two computations which should be identical.

Compiler command lines:
g++ -O3 -march=skylake-avx512 -mprefer-vector-width=512 -o bug_cxx bug_cxx.cxx
gfortran -O3 -march=skylake-avx512 -mprefer-vector-width=512 -o bug_f90
bug_f90.f90

No errors or warnings are encountered at -Wall -Wextra.

gcc -v:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/gpfs/software/juwels/stages/2019a/software/GCCcore/8.3.0/libexec/gcc/x86_64-pc-linux-gnu/8.3.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --enable-languages=c,c++,fortran --enable-lto
--enable-checking=release --disable-multilib --enable-shared=yes
--enable-static=yes --enable-threads=posix --enable-plugins
--enable-gold=default --enable-ld --with-plugin-ld=ld.gold
--prefix=/gpfs/software/juwels/stages/2019a/software/GCCcore/8.3.0
--with-local-prefix=/gpfs/software/juwels/stages/2019a/software/GCCcore/8.3.0
--enable-bootstrap
--with-isl=/dev/shm/swmanage/GCCcore/8.3.0/dummy-/gcc-8.3.0/stage2_stuff
Thread model: posix
gcc version 8.3.0 (GCC)

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

end of thread, other threads:[~2020-04-07  6:39 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-06 13:08 [Bug translation/94500] New: Wrong maximum value with small integer types and AVX-512 ben at rockshrub dot de
2020-04-06 13:09 ` [Bug translation/94500] " ben at rockshrub dot de
2020-04-06 13:59 ` [Bug tree-optimization/94500] " jakub at gcc dot gnu.org
2020-04-06 15:05 ` jakub at gcc dot gnu.org
2020-04-06 15:31 ` jakub at gcc dot gnu.org
2020-04-07  6:28 ` cvs-commit at gcc dot gnu.org
2020-04-07  6:33 ` cvs-commit at gcc dot gnu.org
2020-04-07  6:38 ` cvs-commit at gcc dot gnu.org
2020-04-07  6:39 ` 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).