[PATCH] D91718: [LV] Legalize scalable VF hints
Cullen Rhodes via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 18 08:31:00 PST 2020
c-rhodes created this revision.
c-rhodes added reviewers: sdesmalen, efriedma, fhahn, dmgreen, Meinersbur, ctetreau, craig.topper.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
c-rhodes requested review of this revision.
In the following loop:
void foo(int *a, int *b, int N) {
for (int i=0; i<N; ++i)
a[i + 4] = a[i] + b[i];
}
The loop dependence constrains the VF to a maximum of (4, fixed), which
would mean using `<4 x i32>` as the vector type in vectorization.
Extending this to scalable vectorization, a VF of (4, scalable) implies
a vector type of `<vscale x 4 x i32>`. To determine if this is legal
vscale must be taken into account. For this example, unless
max(vscale)=1, it's unsafe to vectorize.
For SVE, the number of bits in an SVE register is architecturally
defined to be a multiple of 128 bits with a maximum of 2048 bits, thus
the maximum vscale is 16. In the loop above it is therefore unfeasible
to vectorize with SVE. However, in this loop:
void foo(int *a, int *b, int N) {
#pragma clang loop vectorize_width(X, scalable)
for (int i=0; i<N; ++i)
a[i + 32] = a[i] + b[i];
}
As long as max(vscale) multiplied by the number of lanes 'X' doesn't
exceed the dependence distance, it is safe to vectorize. For SVE a VF of
(2, scalable) is within this constraint, since a vector of `<16 x 2 x 32>`
will have no dependencies between lanes. For any number of lanes larger
than this it would be unsafe to vectorize.
This patch extends 'computeFeasibleMaxVF' to legalize scalable VFs
specified as loop hints, implementing the following behaviour:
- Bail out of scalable vectorization if it's unfeasible given the loop dependence, like in the first example above for SVE.
- Accept scalable VFs if it's safe to do so.
- Otherwise, clamp scalable VFs that exceed the maximum safe VF.
A new TTI interface has been added 'getMaxVScale' that returns the
maximum vscale for a given target.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D91718
Files:
llvm/include/llvm/Analysis/TargetTransformInfo.h
llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
llvm/include/llvm/CodeGen/BasicTTIImpl.h
llvm/lib/Analysis/TargetTransformInfo.cpp
llvm/lib/Target/AArch64/AArch64TargetTransformInfo.h
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/test/Transforms/LoopVectorize/AArch64/scalable-vf-hint.ll
llvm/test/Transforms/LoopVectorize/scalable-vf-hint.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91718.306119.patch
Type: text/x-patch
Size: 20811 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201118/1dc783f5/attachment.bin>
More information about the llvm-commits
mailing list