Bug 98522 - _mm_cvttps_pi32 and _mm_cvtps_pi32 raise spurious FP exceptions
Summary: _mm_cvttps_pi32 and _mm_cvtps_pi32 raise spurious FP exceptions
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 11.0
: P3 normal
Target Milestone: 10.3
Assignee: Uroš Bizjak
Depends on:
Reported: 2021-01-05 02:54 UTC by James Y Knight
Modified: 2021-01-06 09:47 UTC (History)
0 users

See Also:
Target: x86_64-*-* i?86-*-*
Known to work:
Known to fail:
Last reconfirmed: 2021-01-05 00:00:00

Proposed patch (898 bytes, patch)
2021-01-05 10:07 UTC, Uroš Bizjak
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description James Y Knight 2021-01-05 02:54:42 UTC
This is a regression due to the MMX in SSE work in GCC10. As far as I can tell, it affects only these two functions.

Example test, which should return 0, but instead throws SIGFPE:

#pragma stdc fenv_access

#define _GNU_SOURCE
#include <emmintrin.h>
#include <fenv.h>

__attribute__((noinline)) __m64 test(__m128 a) {
  return _mm_cvtt_ps2pi(a);

int main() {
  __m128 x = (__m128)(__m128i){0x0000000000000000LL, 0x7fffffffffffffffLL};
  volatile __m64 y = test(x);

In GCC 10 and trunk, the function test is compiled to:
        cvttps2dq       xmm0, xmm0
which will convert the upper 64 bits as well as the lower 64 bits -- and therefore raises FP exceptions accordingly. But, it ought to be ignoring the upper 64bits.
Comment 1 Uroš Bizjak 2021-01-05 10:07:19 UTC
Created attachment 49881 [details]
Proposed patch
Comment 2 Uroš Bizjak 2021-01-06 09:47:52 UTC
Fixed for gcc-10.3.