[PATCH] D129609: [RISCV] Exploit fact that vscale is always power of two to replace urem sequence
Philip Reames via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 12 17:49:38 PDT 2022
reames created this revision.
reames added reviewers: craig.topper, kito-cheng, asb, frasercrmck.
Herald added subscribers: sunshaoce, VincentWu, luke957, ctetreau, StephenFan, vkmr, evandro, luismarques, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, shiva0217, niosHD, sabuasal, bollu, simoncook, johnrusso, rbar, hiraditya, kristof.beyls, arichardson, mcrosier.
Herald added a project: All.
reames requested review of this revision.
Herald added subscribers: alextsao1999, pcwang-thead, eopXD, MaskRay.
Herald added a project: LLVM.
When doing scalable vectorization, the loop vectorizer uses a urem in the computation of the vector trip count. The RHS of that urem is a (possibly shifted) call to @llvm.vscale.
If my understanding of vscale is correct - which, I'm a bit unsure of, so please double check! - then vscale is effectively the number of "blocks" in the vector register. (That is, types such as <vscale x 8 x i8> and <vscale x 1 x i8> both fill one 64 bit block, and vscale is essentially how many of those blocks there are in a single vector register at runtime.)
We know from the specification that VLEN must be a power of two between ELEN and 2^16. Since our block size is 64 bits, the must be a power of two numbers of blocks. (For everything other than VLEN<=32, but that's already broken.)
Careful review here is appreciated. I've been looking for a way to eliminate that urem, and am a bit concerned this seems too easy. I might be missing something.
It is worth noting that AArch64 SVE explicitly allows non-power-of-two sizes for the vector registers and thus can't claim that vscale is a power of two by this logic.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D129609
Files:
llvm/include/llvm/CodeGen/TargetLowering.h
llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
llvm/lib/Target/RISCV/RISCVISelLowering.h
llvm/test/CodeGen/RISCV/rvv/sink-splat-operands.ll
llvm/test/CodeGen/RISCV/rvv/vscale-power-of-two.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129609.444120.patch
Type: text/x-patch
Size: 13880 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220713/6594b74c/attachment.bin>
More information about the llvm-commits
mailing list