https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121534

--- Comment #9 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-15 branch has been updated by Vineet Gupta
<vine...@gcc.gnu.org>:

https://gcc.gnu.org/g:f12a272169523823ff27d69f187f73c4211222ae

commit r15-10250-gf12a272169523823ff27d69f187f73c4211222ae
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>

Reply via email to