[PATCH] D157976: [RISCV] Use materialization cost when lowering constant build_vector
Luke Lau via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 15 06:00:55 PDT 2023
luke created this revision.
luke added reviewers: craig.topper, reames, frasercrmck.
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, kito-cheng, 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.
When lowering a constant build_vector, we currently match the following
patterns in this order:
1. Splats
2. vid sequences
3. <= 32 bit scalar vmv.s.x
4. Hidden splats
5. Dominant values
So if a build_vector could be expressed by both a vid sequence and a vmv.s.x,
then it will always lower it to a vid. However, the vmv.s.x might be a more
profitable lowering if the constants are cheap to materialize, e.g.:
<4 x i8> <i8 1, i8 3, i8 5, i8 7>
Could be lowered as:
vsetivli zero, 4, e8, mf4, ta, ma
vid.v v8
vadd.vv v8, v8, v8
vadd.vi v8, v8, 1
Or as 3 instructions with:
vsetivli zero, 4, e32, m1, ta, ma
lui a0, 28752
vmv.s.x v8, a0
Furthermore, a vid sequence is only lowered if both its step and addend fit
inside an immediate. This means that we always load from the constant pool for
build_vectors like:
<4 x i8> <i8 100, i8 101, i8 102, i8 103>
Even if it can be lowered to just
vid v8
li a0, 100
vadd.vx v8, v8, a0
This patch computes the (rough) cost for vid sequences, scalar vmv.s.x and
hidden splat lowerings, then chooses the cheapest lowering (I've left out
dominant values for now).
An arbitrary maximum cost has been chosen for now, but it should be replaced
with an approximate constant pool load cost.
The result of this is that we get some more vmv.s.xs where there would be vids,
and we get more vids where previously it used a constant pool load.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D157976
Files:
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/CodeGen/RISCV/rvv/active_lane_mask.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-fp-buildvec.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-fp-interleave.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-fp-shuffles.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-int-buildvec.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-int-interleave.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-reduction-int-vp.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-shuffle-reverse.ll
llvm/test/CodeGen/RISCV/rvv/fixed-vectors-store.ll
llvm/test/CodeGen/RISCV/rvv/shuffle-reverse.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D157976.550299.patch
Type: text/x-patch
Size: 61623 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230815/caf379b4/attachment-0001.bin>
More information about the llvm-commits
mailing list