[LoopVectorize] Add support for scalable vectorization of induction variables
authorDavid Sherwood <david.sherwood@arm.com>
Wed, 10 Mar 2021 17:06:47 +0000 (17:06 +0000)
committerDavid Sherwood <david.sherwood@arm.com>
Tue, 30 Mar 2021 10:13:31 +0000 (11:13 +0100)
commita08c7736a771d1be6e3168ff94aa8d7ff4479ef4
treeff2829d7a7274b6cfefb8c3a0cd753507bd2ff25
parentc42c67ad60449fe19949f2664c2a5878b3f72b7e
[LoopVectorize] Add support for scalable vectorization of induction variables

This patch adds support for the vectorization of induction variables when
using scalable vectors, which required the following changes:

1. Removed assert from InnerLoopVectorizer::getStepVector.
2. Modified InnerLoopVectorizer::createVectorIntOrFpInductionPHI to use
   a runtime determined value for VF and removed an assert.
3. Modified InnerLoopVectorizer::buildScalarSteps to work for scalable
   vectors. I did this by calculating the full vector value for each Part
   of the unroll factor (UF) and caching this in the VP state. This means
   that we are always able to extract an arbitrary element from the vector
   if necessary. In addition to this, I also permitted the caching of the
   individual lane values themselves for the known minimum number of elements
   in the same way we do for fixed width vectors. This is a further
   optimisation that improves the code quality since it avoids unnecessary
   extractelement operations when extracting the first lane.
4. Added an assert to InnerLoopVectorizer::widenPHIInstruction, since while
   testing some code paths I noticed this is currently broken for scalable
   vectors.

Various tests to support different cases have been added here:

  Transforms/LoopVectorize/AArch64/sve-inductions.ll

Differential Revision: https://reviews.llvm.org/D98715
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/test/Transforms/LoopVectorize/AArch64/sve-inductions.ll [new file with mode: 0644]