From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id F282A3850425; Sat, 5 Jun 2021 18:40:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F282A3850425 From: "evan@coeus-group.com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/100927] New: [sse2] floating point to integer conversion functions incorrect results w/ NaN constants + optimization Date: Sat, 05 Jun 2021 18:40:27 +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: 11.1.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: evan@coeus-group.com 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 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: Sat, 05 Jun 2021 18:40:28 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100927 Bug ID: 100927 Summary: [sse2] floating point to integer conversion functions incorrect results w/ NaN constants + optimization Product: gcc Version: 11.1.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: target Assignee: unassigned at gcc dot gnu.org Reporter: evan@coeus-group.com Target Milestone: --- _mm_cvttpd_epi32, _mm_cvttpd_pi32, _mm_cvttps_epi32, and _mm_cvttsd_si32 are supposed to return INT32_MIN for NaN inputs. However, when compiled with optimization on GCC, if the values are known at compile time NaN inputs res= ult in 0 in the output. Here is a quick test case, using _mm_cvttpd_epi32: #include #include int main(void) { static const double values[] =3D { __builtin_nan(""), -__builtin_nan("") }; int32_t res[4]; _mm_storeu_si128((__m128i*) res, _mm_cvttpd_epi32(_mm_loadu_pd(values))); for (int i =3D 0 ; i < 4 ; i++) { printf("%d\n", res[i]); } return 0; } Compile with `gcc -O1 -o test test.c` and you get all zeros, `gcc -O0 -o te= st test.c` and the first two elements of the result are INT32_MIN as they shou= ld be. Changing the const to volatile (and adding -Wno-discarded-qualifiers) "fixes" the issue.=