https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122103
--- Comment #10 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Tamar Christina <[email protected]>: https://gcc.gnu.org/g:c10b8f711ea2d34717d645460c64514b92a70431 commit r16-6506-gc10b8f711ea2d34717d645460c64514b92a70431 Author: Tamar Christina <[email protected]> Date: Mon Jan 5 20:53:21 2026 +0000 middle-end: teach gimple_could_trap_p to handle __builtin calls [PR122103] The following testcase void f (float *__restrict c, int *__restrict d, int n) { for (int i = 0; i < n; i++) { if (d[i] > 1000) c[i] = __builtin_sqrtf (c[i]); } } compiled with -O3 -march=armv9-a -fno-math-errno -ftrapping-math vectorizes as: f: cmp w2, 0 ble .L1 mov x3, 0 mov w4, 1000 whilelo p7.s, wzr, w2 mov z31.s, w4 ptrue p6.b, all .L3: ld1w z0.s, p7/z, [x1, x3, lsl 2] cmpgt p7.s, p7/z, z0.s, z31.s ld1w z30.s, p7/z, [x0, x3, lsl 2] fsqrt z30.s, p6/m, z30.s st1w z30.s, p7, [x0, x3, lsl 2] incw x3 whilelo p7.s, w3, w2 b.any .L3 .L1: ret which is incorrect, fsqrt can raise FE exceptions and so should be masked on p7 as the inactive lanes can trigger incorrect FE errors as the code in the PR demonstrates. In GCC 13 this was partially addressed for instruction that got lowered to IFNs through r13-5979-gb9c78605039f839f3c79ad8fca4f60ea9a5654ed but it never addressed __builtin_math_fns. Assuming the direction of travel in PR96373 is still valid this extends the support. While ERRNO trapping is controlled through flags, it looks like for trapping math the calls and IFNs are not marked specifically. Instead in gimple_could_trap_p_1 through operation_could_trap_p we default to all floating point operation could trap if flag_trapping_math. This extends gimple_could_trap_p_1 to do the same for __builtin_math_fns but exclude instructions that the standard says can't raise FEs. gcc/ChangeLog: PR tree-optimization/122103 * gimple.cc (gimple_could_trap_p_1): Handle __builtin_ calls.
