From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 5EFDF385DC08; Mon, 6 Apr 2020 13:08:42 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 5EFDF385DC08 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1586178522; bh=g9LUfihdobPjWEezj5MJ56AJPdzmHpcsm4myr8BB1PM=; h=From:To:Subject:Date:From; b=RRRRroe6EKPTMwJV2UHQID21VhSRDa90bRtWLp+vYBfQiHvf8Hm7URK63d2hAKPxq jq8vhb0EDK12KDQIkAoucfos4XHA1MHRa4M1v7aCE7mnWVY5jSuIDpCPH/tPYHGtpy 5JTKlvxCvGeSN7bq5hUVMHWEj7NRhpJl4RtI9Dhc= From: "ben at rockshrub dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug translation/94500] New: Wrong maximum value with small integer types and AVX-512 Date: Mon, 06 Apr 2020 13:08:42 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: translation X-Bugzilla-Version: 8.3.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: ben at rockshrub dot de X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 06 Apr 2020 13:08:42 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94500 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=3D48211&action=3Dedit 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 t= he 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 G= CC. The attached program fills a vector in a way that triggers the error and th= en 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=3Dskylake-avx512 -mprefer-vector-width=3D512 -o bug_cxx bug_= cxx.cxx gfortran -O3 -march=3Dskylake-avx512 -mprefer-vector-width=3D512 -o bug_f90 bug_f90.f90 No errors or warnings are encountered at -Wall -Wextra. gcc -v: Using built-in specs. COLLECT_GCC=3Dgcc COLLECT_LTO_WRAPPER=3D/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=3Dc,c++,fortran --enable-l= to --enable-checking=3Drelease --disable-multilib --enable-shared=3Dyes --enable-static=3Dyes --enable-threads=3Dposix --enable-plugins --enable-gold=3Ddefault --enable-ld --with-plugin-ld=3Dld.gold --prefix=3D/gpfs/software/juwels/stages/2019a/software/GCCcore/8.3.0 --with-local-prefix=3D/gpfs/software/juwels/stages/2019a/software/GCCcore/8= .3.0 --enable-bootstrap --with-isl=3D/dev/shm/swmanage/GCCcore/8.3.0/dummy-/gcc-8.3.0/stage2_stuff Thread model: posix gcc version 8.3.0 (GCC)=