[PATCH] D128542: [LV] Allow scalable vectorization with vscale = 1

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 24 11:27:57 PDT 2022


reames created this revision.
reames added reviewers: craig.topper, fhahn, hfinkel, david-arm.
Herald added subscribers: luke957, StephenFan, frasercrmck, luismarques, apazos, sameer.abuasal, s.egerton, Jim, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, jrtc27, niosHD, sabuasal, bollu, simoncook, johnrusso, rbar, asb, hiraditya, arichardson, mcrosier.
Herald added a project: All.
reames requested review of this revision.
Herald added subscribers: alextsao1999, pcwang-thead, MaskRay.
Herald added a project: LLVM.

This change is a bit subtle.  If we have a type like <vscale x 1 x i64>, the vectorizer will currently reject vectorization.  The reason is that a type like <1 x i64> is likely to get simply rescalarized, and the vectorizer doesn't want to be in the game of simple unrolling.

(I've given the example in terms of 1 x types which use a single register, but the same issue exists for any N x types which use N registers.  e.g. RISCV LMULs.)

This change distinguishes scalable types from fixed types under the reasoning that converting to a scalable type isn't unrolling.  Because the actual vscale isn't known until runtime, using a vscale type is potentially very profitable.

This makes an important, but unchecked, assumption.  Specifically, the scalable type is assumed to only be legal per the cost model if there's actually a scalable register class which is distinct from the scalar domain.  This is, to my knowledge, true for all targets which return non-invalid costs for scalable vector ops today, but in theory, we could have a target decide to lower scalable to fixed length vector or even scalar registers.  If that ever happens, we'd need to revisit this code.

In practice, this patch unblocks scalable vectorization for ELEN types on RISCV.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128542

Files:
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
  llvm/test/Transforms/LoopVectorize/RISCV/scalable-basics.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128542.439825.patch
Type: text/x-patch
Size: 14524 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220624/7826a08e/attachment.bin>


More information about the llvm-commits mailing list