[RISCV] Optimize "dominant element" BUILD_VECTORs
authorFraser Cormack <fraser@codeplay.com>
Mon, 15 Mar 2021 15:52:16 +0000 (15:52 +0000)
committerFraser Cormack <fraser@codeplay.com>
Wed, 17 Mar 2021 10:09:04 +0000 (10:09 +0000)
commit70251759a29830a2c0aca146d91bbe65e0f1df0c
tree9d590c37f0ef699afe9ae10f9e1b4532515798e8
parent967b64beb4bf953f452a2866716065e8bbcb5d2f
[RISCV] Optimize "dominant element" BUILD_VECTORs

This patch adds an optimization path for BUILD_VECTOR nodes where the
majority of the elements are identical. These can be splatted, with the
remaining elements patched up with INSERT_VECTOR_ELTs. The threshold can
be tweaked as required - it is currently conservative. Undef elements
are disregarded when judging the dominance of a particular element. This
allows them to be covered by the splat value.

In addition, vectors of 2 elements are always optimized to a splat (for
the upper element) and an insert at element zero.

This optimization is disabled when optimizing for size.

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D98700
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-bswap.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-ctlz.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-cttz.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-fp-buildvec.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-insert.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-int-buildvec.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-int.ll