| Issue |
242732
|
| Summary |
[RISCV] Debug uses block VL reduction in RISCVVLOptimizer
|
| Labels |
backend:RISC-V,
debuginfo
|
| Assignees |
|
| Reporter |
yqtian-se
|
With `-g`, `RISCVVLOptimizer` does not reduce the VL of a vector add whose
result has a debug value, so the code differs from `-g0`.
Reproducer (`input.c`):
```c
#include <riscv_vector.h>
vint32m1_t f(vint32m1_t a, vint32m1_t b, size_t n) {
vint32m1_t x = __riscv_vadd_vv_i32m1(a, b, (size_t)-1);
size_t vl = __riscv_vsetvl_e32m1(n);
return __riscv_vadd_vv_i32m1(x, b, vl);
}
```
```sh
clang --target=riscv64-linux-gnu -march=rv64gcv -O2 -ffreestanding -g -c input.c -o g.o
clang --target=riscv64-linux-gnu -march=rv64gcv -O2 -ffreestanding -g0 -c input.c -o g0.o
llvm-objdump -d --no-show-raw-insn -j .text g.o > g.txt
llvm-objdump -d --no-show-raw-insn -j .text g0.o > g0.txt
diff g0.txt g.txt
```
Actual (`-g0` vs `-g`, LLVM main `9ce8918945cf`):
```diff
- vsetvli zero, a0, e32, m1, ta, ma
+ vsetvli a1, zero, e32, m1, ta, ma
vadd.vv v8, v8, v9
+ vsetvli zero, a0, e32, m1, ta, ma
vadd.vv v8, v8, v9
```
Expected: the first `vadd.vv` runs with the reduced VL under `-g` too.
**Possible cause.** The `DBG_VALUE` of `x` is a user of the first `vadd`:
- `checkUsers` walks `use_operands()`, so it reaches the `DBG_VALUE`, which has
no SEW operand and makes it give up.
- `tryReduceVL`
(https://github.com/llvm/llvm-project/blob/9ce8918945cf/llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp#L1366) can only use the new
VL if the instruction is moved after the VL definition (`vsetvl` of `n`). It
requires every same-block use to be dominated by that definition, and the
`DBG_VALUE`, which sits right after the `vadd` and before the `vsetvl`, is
not.
**Why ignoring the debug use is not enough.** If both checks skip debug users,
`tryReduceVL` splices the `vadd` after the VL definition while its `DBG_VALUE`
stays in front of it, so the debug value would refer to a register before its
definition. The debug users would have to be moved with the instruction, or
set undef.
Related: #230319 fixed debug uses in the RISC-V vector peephole, a different pass.
This issue is assisted by Claude and reviewed by yqtian-se.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs