For the vector that should be splitted, legalizer would use stack store/load to make it. This patch adds cost model by counting stack store/load and scalar store/load cost.

# Details

# Diff Detail

- Repository
- rG LLVM Github Monorepo

### Event Timeline

Does the proposed costing match the current lowering? I haven't looked.

I would expect the lowering to be able to do the following:

- For a constant index w/ fixed vectors, emit a single extract/insert into a particular split register value.
- For a constant index w/ scalable vectors, emit a single instruction when index < minimum VLEN implied VLMAX.
- Use a sequence of masked slidedowns to extract an arbitrary index from an arbitrary set of vector registers. Or possibly a vcompress instead.

The spill/load lowering is legal, but rather sub-optimal.

I made some mistake before. Now the legalizer will do the following action:

For constant index:

- All fixed length vector would lower to a single extract/insert
- For scalable vector, if we could make sure that the index is in the first splitted vector, lower to a single extract/insert; otherwise use stack spill and load/store.

For non constant index:

All would use stack spill and load/store.

Can you add some test coverage specifically for the insert/extract case as opposed to relying on updates in lowering of more complicated constructs?

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp | ||
---|---|---|

1456 | I believe that for a scalable vector, this effectively returns the M in <vscale x M x iN>. While correct, this is smaller than the maximum index we can prove in the first vector. (e.g. for +v, M is 1 for i64, but provably valid indexes are 0 and 1) Here's an alternative: unsigned EltSize = VT.getScalarSizeInBits(); unsigned MinSize = VT.getSizeInBits().getKnownMinValue(); unsigned VectorBitsMin = Subtarget.getRealMinVLen(); unsigned MinVLMAX = RISCVTargetLowering::computeVLMAX(VectorBitsMin, EltSize, MinSize); |

Done, I added in https://reviews.llvm.org/D135534.

llvm/lib/Target/RISCV/RISCVTargetTransformInfo.cpp | ||
---|---|---|

1456 | Yes, I agree with you, but this cost should obey |