[LV] Still vectorise when tail-folding can't find a primary inducation variable
authorSjoerd Meijer <sjoerd.meijer@arm.com>
Thu, 9 Jan 2020 09:14:00 +0000 (09:14 +0000)
committerSjoerd Meijer <sjoerd.meijer@arm.com>
Thu, 9 Jan 2020 09:14:00 +0000 (09:14 +0000)
commit8f1887456ab4ba24a62ccb19d0d04b08972a0289
tree3a92e6feac6510155c993b9550c913d57860f0fc
parent08778d8c4fd8a6519c7f27bfa6b09c47262cb844
[LV] Still vectorise when tail-folding can't find a primary inducation variable

This addresses a vectorisation regression for tail-folded loops that are
counting down, e.g. loops as simple as this:

  void foo(char *A, char *B, char *C, uint32_t N) {
    while (N > 0) {
      *C++ = *A++ + *B++;
       N--;
    }
  }

These are loops that can be vectorised, but when tail-folding is requested, it
can't find a primary induction variable which we do need for predicating the
loop. As a result, the loop isn't vectorised at all, which it is able to do
when tail-folding is not attempted. So, this adds a check for the primary
induction variable where we decide how to lower the scalar epilogue. I.e., when
there isn't a primary induction variable, a scalar epilogue loop is allowed
(i.e. don't request tail-folding) so that vectorisation could still be
triggered.

Having this check for the primary induction variable make sense anyway, and in
addition, in a follow-up of this I will look into discovering earlier the
primary induction variable for counting down loops, so that this can also be
tail-folded.

Differential revision: https://reviews.llvm.org/D72324
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/test/Transforms/LoopVectorize/ARM/tail-folding-counting-down.ll [new file with mode: 0644]
llvm/test/Transforms/LoopVectorize/tail-folding-counting-down.ll [new file with mode: 0644]