From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 564103857829; Fri, 30 Jul 2021 02:30:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 564103857829 From: "bartoldeman at users dot sourceforge.net" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/101683] New: Floating point exception for double->unsigned conversion on avx512 only Date: Fri, 30 Jul 2021 02:30:04 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 10.3.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: bartoldeman at users dot sourceforge.net 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: Fri, 30 Jul 2021 02:30:04 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D101683 Bug ID: 101683 Summary: Floating point exception for double->unsigned conversion on avx512 only Product: gcc Version: 10.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: bartoldeman at users dot sourceforge.net Target Milestone: --- Created attachment 51222 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D51222&action=3Dedit File to reproduce For this code: #define _GNU_SOURCE #include int main(int argc, char **argv) { feenableexcept(FE_INVALID); double argcm10 =3D argc / -0.1; return (unsigned)(argcm10 < 0.0 ? 0 : argcm10); } $ gcc -O -march=3Dskylake-avx512 fpexcept.c -lm $ ./a.out=20 Floating point exception the instructions vcvttsd2usi %xmm0, %eax vxorpd %xmm1, %xmm1, %xmm1 vucomisd %xmm0, %xmm1 movl $0, %edx cmova %edx, %eax are generated just after the division, so the conversion happens before the comparison. "If a converted result cannot be represented in the destination format, the floating-point invalid exception is raised, and if this exception is masked, the integer value 2^w =E2=80=93 1 is returned, where w represents the numbe= r of bits in the destination format." so when masked, for argcm10 =3D -10.0 the value 2^w-1 is discarded and all = is well, since it's < 0, but not when unmasked. I can reproduce this issue with 9.3 as well, but not with 8.4 (the generated code is correct for 8.4). I have not tried 11.1 yet. Note: I found this issue with the UCX library when compiled with -march=3Dskylake-avx512, this example is stripped down from: https://github.com/openucx/ucx/blob/f5362f5e6f80d930b88c44c63b4d8d71cf91d21= 4/src/ucp/core/ucp_ep.c#L2699=