[PATCH] D153351: [RISCV] Fold vmv.v.v into vops

Luke Lau via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 20 07:34:03 PDT 2023


luke created this revision.
luke added reviewers: reames, craig.topper, arcbbb, fakepaper56, frasercrmck, kito-cheng.
Herald added subscribers: jobnoorman, asb, pmatos, VincentWu, vkmr, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya, arichardson.
Herald added a project: All.
luke requested review of this revision.
Herald added subscribers: llvm-commits, wangpc, eopXD, MaskRay.
Herald added a project: LLVM.

A vmv.v.v can be thought of a vmerge, where instead of masking with a mask,
we're masking the tail with VL. For example, in the sequence below the vmv.v.v
copies over the first 2 elements from the vadd.vv:

vsetivli zero, 4, e32, m1, ta, ma
vadd.vv v9, v10, v11
vsetivli zero, 2, e32, m1, tu, ma
vmv.v.v v8, v9

This patch adds an optimisation to fold away the vmv.v.v into the preceding op
if it has only use, by modifying the op's VL:

vsetivli zero, 2, e32, m1, ta, ma
vadd.vv v8, v10, v11

In general, we can just replace the VL of the op with the VL of the vmv.v.v
(Unless it's a load, in which case we make sure we're only loading a VL less
than or equal to the original, so we don't end up loading more elements than
before)

The actual optimisation shares largely the same structure as 
performCombineVMergeAndVOps: I've just duplicated the code for now, but if 
people wanted I could try and abstract some of the shared bits away.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153351

Files:
  llvm/lib/Target/RISCV/RISCVISelDAGToDAG.cpp
  llvm/lib/Target/RISCV/RISCVISelDAGToDAG.h
  llvm/test/CodeGen/RISCV/rvv/combine-vmv.ll
  llvm/test/CodeGen/RISCV/rvv/extract-subvector.ll
  llvm/test/CodeGen/RISCV/rvv/fixed-vectors-insert-subvector-shuffle.ll
  llvm/test/CodeGen/RISCV/rvv/fixed-vectors-insert-subvector.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153351.532923.patch
Type: text/x-patch
Size: 19639 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230620/a2c36d68/attachment-0001.bin>


More information about the llvm-commits mailing list