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

--- Comment #2 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:fd042192094c456e275c53dfe92383bec1e9fca3

commit r16-1291-gfd042192094c456e275c53dfe92383bec1e9fca3
Author: Vineet Gupta <vine...@rivosinc.com>
Date:   Sun Jun 8 14:55:11 2025 -0700

    RISC-V: frm/mode-switch: robustify call_insn backtracking [PR120203]

    As described in prior patches of this series, FRM mode switching state
    machine has special handling around calls. After a call_insn, if in
DYN_CALL
    state, it needs to transition back to DYN, which requires back checking
    if prev insn was indeed a call.

    Defering/delaying this could lead to unncessary final transitions leading
    to extraenous FRM save/restores.

    However the current back checking of call_insn was too coarse-grained.
    It used prev_nonnote_nondebug_insn_bb () which implies current insn to
    be in the same BB as the call_insn, which need not always be true.
    The problem is not with the API, but the use thereof.

    Fix this by tracking call_insn more explicitly in TARGET_MODE_NEEDED.
     - On seeing a call_insn, record a "call note".
     - On subsequent insns if a "call note" is seen, do the needed state switch
       and clear the note.
     - Remove the old BB based search.

    The number of FRM read/writes across SPEC2017 -Ofast -mrv64gcv improves.

                           Before                 After
                       -------------        ---------------
                      frrm fsrmi fsrm       frrm fsrmi frrm
       perlbench_r      17    0    1          17    0    1
          cpugcc_r      11    0    0          11    0    0
          bwaves_r      16    0    1          16    0    1
             mcf_r      11    0    0          11    0    0
      cactusBSSN_r      19    0    1          19    0    1
            namd_r      14    0    1          14    0    1
          parest_r      24    0    1          24    0    1
          povray_r      26    1    6          26    1    6
             lbm_r       6    0    0           6    0    0
         omnetpp_r      17    0    1          17    0    1
             wrf_r    1268   13 1603         613   13   82
        cpuxalan_r      17    0    1          17    0    1
          ldecod_r      11    0    0          11    0    0
            x264_r      11    0    0          11    0    0
         blender_r      61   12   42          39   12   16
            cam4_r      45   13   20          40   13   17
       deepsjeng_r      11    0    0          11    0    0
         imagick_r     132   16   25          33   16   18
           leela_r      12    0    0          12    0    0
             nab_r      13    0    1          13    0    1
       exchange2_r      16    0    1          16    0    1
       fotonik3d_r      19    0    1          19    0    1
            roms_r      21    0    1          21    0    1
              xz_r       6    0    0           6    0    0
                   -----------------        --------------
                      1804   55 1707        1023   55  150
                   -----------------        --------------
                                3566                  1228
                   -----------------        --------------

    While this was a missed-optimization exercise, testing exposed a latent
    bug as additional testsuite failure, captured as PR120203. The existing
    test float-point-dynamic-frm-74.c was missing FRM save after a call
    which this fixes (as a side-effect of robust call state tracking).

    |    frrm    a5
    |    fsrmi   1
    |
    |    vfadd.vv v1,v8,v9
    |    fsrm    a5
    |    beq     a1,zero,.L2
    |
    |    call    normalize_vl_1
    |    frrm    a5
    |
    | .L3:
    |    fsrmi   3
    |    vfadd.vv v8,v8,v9
    |    fsrm    a5
    |    jr      ra
    |
    | .L2:
    |    call    normalize_vl_2
    |    frrm    a5               <-- missing
    |    j       .L3

            PR target/120203

    gcc/ChangeLog:

            * config/riscv/riscv.cc (CFUN_IN_CALL): New macro.
            (struct mode_switching_info): Add new field.
            (riscv_frm_adjust_mode_after_call): Remove.
            (riscv_frm_mode_needed): Track call_insn.

    gcc/testsuite/ChangeLog:

            * gcc.target/riscv/rvv/base/float-point-dynamic-frm-74.c: Expect
            an additional FRRM.

    Signed-off-by: Vineet Gupta <vine...@rivosinc.com>
  • [Bug target/120203] RISC-V: Frm... cvs-commit at gcc dot gnu.org via Gcc-bugs

Reply via email to