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

            Bug ID: 127936
           Summary: RISC-V: -g prevents singleton VXRM hoisting at
                    function entry
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: compare-debug-failure
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yqtian668 at gmail dot com
  Target Milestone: ---
            Target: riscv64-unknown-linux-gnu

Created attachment 65869
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=65869&action=edit
Proposed patch and regression tests

On GCC trunk, enabling debug information changes where a RISC-V VXRM write is
placed.  The reproducer is the existing GCC testcase
`gcc.target/riscv/rvv/base/vxrm-12.c`.

Tested revision:

```text
40b414ce63a5448495df9161aea0bfb495b47c11
```

It reproduces with:

```sh
riscv64-unknown-linux-gnu-gcc -O3 -march=rv64gcv -mabi=lp64d \
  -fcompare-debug -S vxrm-12.c
```

GCC reports:

```text
cc1: error: vxrm-12.c: '-fcompare-debug' failure (length)
```

The first ordinary difference is:

```diff
 f:
-  csrwi vxrm,2
   ble   a3,zero,.L5
+  csrwi vxrm,2
```

Without debug information, the singleton-VXRM optimization places the write at
function entry.  With `-g`, GCC inserts a non-executing debug instruction at
the beginning of the function.  `riscv_mode_needed` compares the current real
instruction with `get_first_nonnote_insn ()`, which returns that debug
instruction.  The mode-switching hook is called only for real instructions, so
the comparison cannot succeed and the entry-hoisting shortcut is disabled.

Skipping a leading debug instruction before making this comparison restores
the same placement with and without `-g`.  A focused DejaGNU test also checks
that `csrwi vxrm,2` remains before the loop guard, so the test cannot pass
merely
because both compilations stopped performing the optimization.  The test has
one failure and two unresolved checks before the fix, and three expected passes
after it.  The complete `vxrm*` selection has 36 expected passes with the fix.

This is related to PR target/127086, which concerns cases where ordinary LCM
does not hoist VXRM writes.  It does not cover debug information disabling the
singleton shortcut.

Expected result: a non-executing debug instruction at function entry should not
change VXRM mode-switch placement.

Reply via email to