https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66462
--- Comment #27 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jeff Law <[email protected]>: https://gcc.gnu.org/g:5cc9ef64063c45cac1d67fcdaba9258fbaf21a8c commit r17-4525-g5cc9ef64063c45cac1d67fcdaba9258fbaf21a8c Author: Matt Turner <[email protected]> Date: Mon Sep 21 07:29:37 2026 -0600 [PATCH 5/5] builtins: build fpclassify on the classification optabs [PR66462] A target defines the isnan, isinf and isnormal optabs when FP comparisons are unsuitable for classification, and fold_builtin_interclass_mathfn leaves those built-ins alone when it does. fold_builtin_fpclassify does not: it always expands into comparisons, so __builtin_fpclassify keeps the problems the individual built-ins were fixed to avoid. On AArch64 with -fsignaling-nans, where all three optabs are now available, fpclassify still raises FE_INVALID for a signaling NaN, as it does on LoongArch, which defines the same three optabs under that flag; on Alpha without -mieee a comparison against a subnormal operand traps or flushes it to zero, so FP_SUBNORMAL cannot be told from FP_ZERO. When all three optabs are available for the mode, build fpclassify on the corresponding built-ins instead, and test zero versus subnormal by shifting the sign bit out of the encoding rather than by comparing against zero, which would reintroduce the same problem. That shift is only valid for a binary format whose sign is a single bit at the top of the matching integer mode, so formats like XFmode, whose encoding is narrower than that mode, and the composite formats, whose sign bit cannot be shifted out, keep the generic expansion. With -fsignaling-nans on AArch64, fpclassify of a double becomes: fmov x1, d0 mov x2, -9007199254740992 mov w0, 0 cmp x2, x1, lsl 1 bcc .L1 mov w0, 1 cmp x2, x1, lsl 1 beq .L1 ubfx x2, x1, 52, 11 mov w0, 4 sub x2, x2, #1 cmp x2, 2045 bls .L1 cmp xzr, x1, lsl 1 cset w0, ne add w0, w0, 2 .L1: ret gcc/ChangeLog: PR middle-end/66462 * builtins.cc (fold_builtin_fpclassify): Expand using the classification built-ins when their optabs are available. gcc/testsuite/ChangeLog: PR middle-end/66462 * gcc.target/aarch64/pr66462-2.c: New test. * gcc.target/alpha/fp-classify-5.c: New test. * gcc.target/alpha/fp-classify-6.c: New test.
