https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115161
--- Comment #21 from Sergei Trofimovich <slyfox at gcc dot gnu.org> --- Shrunk the example down to a single simpler function while preserving the original masking intent: ```c cat bug.cc #include <stdint.h> #include <string.h> #include <emmintrin.h> __attribute__((noipa)) static void assert_eq_p(void * l, void * r) { char lb[16]; char rb[16]; __builtin_memcpy(lb, l, 16); __builtin_memcpy(rb, r, 16); if (__builtin_memcmp(lb, rb, 16) != 0) __builtin_trap(); } __attribute__((noipa)) static void assert_eq(__m128i l, __m128i r) { assert_eq_p(&l, &r); } int main() { const __m128i su = _mm_set1_epi32(0x4f800000); const __m128 sf = _mm_castsi128_ps(su); const __m128 overflow_mask_f32 = _mm_cmpge_ps(sf, _mm_set1_ps(2147483648.0f)); const __m128i overflow_mask = _mm_castps_si128(overflow_mask_f32); const __m128i conv = _mm_cvttps_epi32(sf); // overflows const __m128i yes = _mm_set1_epi32(INT32_MAX); const __m128i a = _mm_and_si128(overflow_mask, yes); const __m128i na = _mm_andnot_si128(overflow_mask, conv); const __m128i conv_masked = _mm_or_si128(a, na); const __m128i actual = _mm_cmpeq_epi32(conv_masked, _mm_set1_epi32(INT32_MAX)); const __m128i expected = _mm_set1_epi32(-1); assert_eq(expected, actual); } ``` The discrepancy: Ok: $ /tmp/gb/gcc/xg++ -Wall -B/tmp/gb/gcc bug.cc -o bug -O0 && ./bug Bad: $ /tmp/gb/gcc/xg++ -Wall -B/tmp/gb/gcc bug.cc -o bug -O2 && ./bug Illegal instruction (core dumped)