https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128229
--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Hongyu Wang <[email protected]>: https://gcc.gnu.org/g:296590f82449d4874af1dbbdc7d9427a288013fb commit r17-6305-g296590f82449d4874af1dbbdc7d9427a288013fb Author: Sun, Qin <[email protected]> Date: Fri Nov 13 14:23:28 2026 +0800 i386: Implement TARGET_UNSPEC_MAY_TRAP_P for trapping SSE/AVX/x87 UNSPECs i386 did not define TARGET_UNSPEC_MAY_TRAP_P, so default_unspec_may_trap_p was used. It brought false negatives on UNSPEC_FIX_NOTRUNC (integer result) and UNSPEC_IEEE_MIN/MAX (vector float mode). Under -ftrapping-math, these UNSPECs could then be hoisted above the guard that keeps them from executing on a NaN, raising a spurious FE_INVALID. Implement the hook as an opt-out: under -ftrapping-math, any UNSPEC with a non-BFmode floating-point operand or result is treated as trapping, except those documented as never raising floating-point exceptions. New UNSPECs are treated as trapping unless explicitly added to the list. As -ftrapping-math is the default, conditionally executed intrinsics such as _mm_min_ps and _mm_cvtps_epi32 are no longer hoisted, if-converted or speculated at plain -O2. That is correct: these instructions do raise exceptions on NaN inputs. gcc/ChangeLog: PR target/128229 * config/i386/i386.cc (ix86_unspec_may_trap_p): New. (TARGET_UNSPEC_MAY_TRAP_P): Define. gcc/testsuite/ChangeLog: PR target/128229 * gcc.target/i386/pr128229-1.c: New test. * gcc.target/i386/pr128229-2.c: Ditto. * gcc.target/i386/pr128229-3.c: Ditto. * gcc.target/i386/pr128229-4.c: Ditto. * gcc.target/i386/pr128229-5.c: Ditto.
