https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127785
--- Comment #9 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The releases/gcc-16 branch has been updated by Igor Shevlyakov <[email protected]>: https://gcc.gnu.org/g:9954ab48cfdfd4accb54885ea6bfdf8709a97579 commit r16-9833-g9954ab48cfdfd4accb54885ea6bfdf8709a97579 Author: Igor Shevlyakov <[email protected]> Date: Thu Oct 22 20:16:36 2026 -0700 match.pd: Keep the ORDERED & NE to LTGT fold quiet [PR127785] ORDERED and NE do not raise an invalid operation exception for a quiet NaN, but LTGT does. The (ordered & ne) -> ltgt rule added with "i386: Optimize ordered and nonequal" has no trapping-math check, so !__builtin_isunordered (a, b) & (a != b) raises FE_INVALID for a NaN operand even at -O0, since the rule also fires in GENERIC. On x86 the result is a signaling comiss. Fold only with -fno-trapping-math or when NaNs are not honored, as the (ltgt @0 @0) rule next to it does. GCC has no quiet comparison code for "ordered and not equal", so under the default flags the two comparisons stay separate, and x86 goes back to the quiet ucomiss/setp/setnp sequence that the rule replaced. The tests added with the rule check the fold itself, so they now pass -fno-trapping-math. With that option GENERIC can already fold the && forms through combine_comparisons, so opt-ordered-and-nonequal-1.c scans the optimized dump instead of forwprop1. The new opt-ordered-and-nonequal-2.c checks that the default flags keep <> out, and cmp-of-cmp-fenv-1.c checks at run time that FE_INVALID is not raised. Assisted-by: Claude Opus 5.5 PR middle-end/127785 gcc/ChangeLog: * match.pd ((ordered @0 @1) & (ne @0 @1)): Only fold to LTGT without trapping math or when NaNs are not honored. gcc/testsuite/ChangeLog: * gcc.dg/opt-ordered-and-nonequal-1.c: Add -fno-trapping-math and scan the optimized dump. * gcc.dg/opt-ordered-and-nonequal-2.c: New test. * gcc.dg/torture/cmp-of-cmp-fenv-1.c: New test. * gcc.target/i386/opt-comi-1.c: Add -fno-trapping-math. * gcc.target/i386/avx10_2-compare-1b.c: Likewise. Signed-off-by: Igor Shevlyakov <[email protected]>
