https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121534
--- Comment #7 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Vineet Gupta <vine...@gcc.gnu.org>: https://gcc.gnu.org/g:f5696e9b1113b0a8e464cabb8cc26c871b1d9289 commit r16-3220-gf5696e9b1113b0a8e464cabb8cc26c871b1d9289 Author: Vineet Gupta <vine...@rivosinc.com> Date: Wed Aug 13 20:20:34 2025 -0700 RISC-V: fix __builtin_round clobbering FP exceptions flags [PR121534] __builtin_round() fails to save/restore FP exception flags around the FP compare insn which can potentially clobber the same. Worth noting that the fflags restore bracketing is slightly different than the glibc implementation. Both FLT and FCVT can potentially clobber fflags. gcc generates below where even if branch is not taken and FCVT is not executed, FLT still executed. Thus FSFLAGS is placed AFTER the label 'L3'. glibc implementation FLT can't clobber due to early NaN check, so FSFLAGS can be moved under the branch, before the label. | convert_float_to_float_round | ... | frflags a5 | fabs.s fa5,fa0 | flt.s a4,fa5,fa4 <--- can clobber fflags | beq a4,zero,.L3 | fcvt.w.s a4,fa0,rmm <--- also | fcvt.s.w fa5,a4 | fsgnj.s fa0,fa5,fa0 | .L3: | fsflags a5 <-- both code paths Fixes: f652a35877e3 ("This is almost exclusively Jivan's work....") PR target/121534 gcc/ChangeLog: * config/riscv/riscv.md (round_pattern): save/restore fflags. gcc/testsuite/ChangeLog: * gcc.target/riscv/rvv/autovec/vls/math-nearbyint-1.c: Adjust scan pattern for additional instances of frflags/fsrflags. Signed-off-by: Vineet Gupta <vine...@rivosinc.com>