public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/100927] New: [sse2] floating point to integer conversion functions incorrect results w/ NaN constants + optimization
@ 2021-06-05 18:40 evan@coeus-group.com
  2023-02-12  9:15 ` [Bug target/100927] " michael.crusoe at gmail dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: evan@coeus-group.com @ 2021-06-05 18:40 UTC (permalink / raw)
  To: gcc-bugs

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

            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 result
in 0 in the output.

Here is a quick test case, using _mm_cvttpd_epi32:


#include <xmmintrin.h>
#include <stdio.h>

int main(void) {
  static const double values[] = {
    __builtin_nan(""), -__builtin_nan("")
  };
  int32_t res[4];

  _mm_storeu_si128((__m128i*) res, _mm_cvttpd_epi32(_mm_loadu_pd(values)));

  for (int i = 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 test
test.c` and the first two elements of the result are INT32_MIN as they should
be.  Changing the const to volatile (and adding -Wno-discarded-qualifiers)
"fixes" the issue.

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

end of thread, other threads:[~2024-06-05  4:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-05 18:40 [Bug target/100927] New: [sse2] floating point to integer conversion functions incorrect results w/ NaN constants + optimization evan@coeus-group.com
2023-02-12  9:15 ` [Bug target/100927] " michael.crusoe at gmail dot com
2023-02-12  9:20 ` pinskia at gcc dot gnu.org
2023-02-12 11:42 ` michael.crusoe at gmail dot com
2023-02-13  6:53 ` crazylht at gmail dot com
2024-06-05  4:09 ` cvs-commit 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).