| Issue |
244901
|
| Summary |
[ARM][MVE] Debug values change VPNOT/VCMP rewrites in arm-mve-vpt-opts
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
yqtian-se
|
In `MVETPAndVPTOptimisations`, `DBG_VALUE`s of predicate (VCCR) registers are treated as
ordinary writes and uses, so `-g` and `-g0` give different code for Armv8.1-M MVE. This is in
three places:
1. `IsWritingToVCCR` checks that operand 0 is a virtual VCCR register but not that it is a def.
`DBG_VALUE %p:vccr` therefore counts as a VCCR write. In `ReplaceVCMPsByVPNOTs` it resets
`PrevVCMP`, so an opposite VCMP is kept instead of becoming a VPNOT. In
`ReduceOldVCCRValueUses` it changes the tracked `VCCRValue` (first loop) or ends the scan
(second loop).
2. The second loop of `ReduceOldVCCRValueUses` uses `findRegisterUseOperand(VCCRValue)`, which also
matches a `DBG_VALUE`. A VPNOT is inserted for the debug instruction and the values are swapped,
so `-g` gets two extra `vpnot`s.
3. `MoveVPNOTBeforeFirstUser` does not skip debug instructions. A `DBG_VALUE` of the VPNOT result
counts as its first user, so the VPNOT is not moved.
Reproducer (LLVM main 3f3bd3f9e0bc), with one function per case:
```c
typedef short v8hi __attribute__((ext_vector_type(8)));
typedef _Bool v8b __attribute__((ext_vector_type(8)));
void g(void);
void h(void);
void extra_vpnots(v8hi a, v8hi b, int c, short *o) {
v8b p;
if (c) { p = __builtin_convertvector(a > b, v8b); g(); }
else { p = __builtin_convertvector(a < b, v8b); h(); }
__builtin_masked_store(~p, a + b, o);
v8b r = p;
__builtin_masked_store(~p, a - b, o + 16);
}
void vpnot_not_moved(v8hi a, v8hi b, int c, short *o) {
v8b p;
if (c) { p = __builtin_convertvector(a > b, v8b); g(); }
else { p = __builtin_convertvector(a < b, v8b); h(); }
v8b q = ~p;
__builtin_masked_store(p, a * b, o + 8);
__builtin_masked_store(q, a + b, o);
}
void vcmp_kept(v8hi a, v8hi b, int c, short *o) {
v8b p;
if (c) { p = __builtin_convertvector(a > b, v8b); g(); }
else { p = __builtin_convertvector(a < b, v8b); h(); }
__builtin_masked_store(__builtin_convertvector(a == b, v8b), a + b, o);
v8b r = p;
__builtin_masked_store(__builtin_convertvector(a != b, v8b), a - b, o + 16);
__builtin_masked_store(p, a * b, o + 32);
}
```
```
clang --target=thumbv8.1m.main-none-eabi -march=armv8.1-m.main+mve.fp -mfloat-abi=hard -O2 -g0 -c t.c -o g0.o
clang --target=thumbv8.1m.main-none-eabi -march=armv8.1-m.main+mve.fp -mfloat-abi=hard -O2 -g -c t.c -o g.o
llvm-objcopy --strip-debug g.o; llvm-objdump -d --no-show-raw-insn g0.o > g0.s; llvm-objdump -d --no-show-raw-insn g.o > g.s
```
`-g0` vs `-g`:
```
extra_vpnots: -g adds vpnot / vpnot around the second masked store
vpnot_not_moved: -g0: vadd.i16 q0, q4, q5 ; vpnot -g: vpnot ; vadd.i16 q0, q4, q5
vcmp_kept: -g0: vpnot ; vpst -g: vpt.i16 ne, q5, q4
```
Adding `-debugify-and-strip-all-safe` to the existing
`llvm/test/CodeGen/Thumb2/mve-vpt-optimisations.mir` also changes its output.
Suggested fix: have `IsWritingToVCCR` require `getOperand(0).isDef()`, and skip debug instructions in
the second loop of `ReduceOldVCCRValueUses` and in `MoveVPNOTBeforeFirstUser`. When the VPNOT is
moved, the `DBG_VALUE`s of its result that it passes should move with it, so they stay after the
def. I can put up a PR with this and the debugify RUN line, plus MIR tests for the two cases
debugify does not produce.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs