[RISCV] Use vmv.v.i for insertion into lane 0 of undef vector when profitable
authorPhilip Reames <preames@rivosinc.com>
Tue, 13 Dec 2022 15:54:46 +0000 (07:54 -0800)
committerPhilip Reames <listmail@philipreames.com>
Tue, 13 Dec 2022 15:54:46 +0000 (07:54 -0800)
commit8adde6941a4b31bbabab41f03dda76c4a05c94b1
tree38204eb3cf0dd294b91df0663248bed6a8748d8f
parent8e6c309451287091d7f79345c1b5c058a52cd13e
[RISCV] Use vmv.v.i for insertion into lane 0 of undef vector when profitable

If we're initializing lane 0 of an undef vector, we can optionally write to other lanes of the vector. Doing so may require additional work, so we don't want to e.g. always use a splat. However, since we don't have an immediate form of vmv.s.x it's useful to use a vmv.v.i if the work required is expected to be equal in practice.  We restrict this to when LMUL <= 1 to a) prevent doing additional work at higher LMULs, and b) avoid overconstraining the register allocator.

At the moment, the new utility is only used by one case in INSERT_VECTOR_ELT lowering. My expectation is that we will reuse this in a couple other places, but each of those deserve individual review.

This change is inspired by D137530, but is not directly related to it. I vaguely remember we discussed the tradeoffs of using vmv.v.i in another recent review, but couldn't find it.

Differential Revision: https://reviews.llvm.org/D139648
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-extract.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-int-buildvec.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-int-shuffles.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-int.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-stepvector.ll