diff options
author | Sjoerd Meijer <sjoerd.meijer@arm.com> | 2020-01-09 09:14:00 +0000 |
---|---|---|
committer | Sjoerd Meijer <sjoerd.meijer@arm.com> | 2020-01-09 09:14:00 +0000 |
commit | 8f1887456ab4ba24a62ccb19d0d04b08972a0289 (patch) | |
tree | 3a92e6feac6510155c993b9550c913d57860f0fc /llvm/test/Transforms/LoopVectorize/tail-folding-counting-down.ll | |
parent | 08778d8c4fd8a6519c7f27bfa6b09c47262cb844 (diff) | |
download | bcm5719-llvm-8f1887456ab4ba24a62ccb19d0d04b08972a0289.tar.gz bcm5719-llvm-8f1887456ab4ba24a62ccb19d0d04b08972a0289.zip |
[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
Diffstat (limited to 'llvm/test/Transforms/LoopVectorize/tail-folding-counting-down.ll')
-rw-r--r-- | llvm/test/Transforms/LoopVectorize/tail-folding-counting-down.ll | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/llvm/test/Transforms/LoopVectorize/tail-folding-counting-down.ll b/llvm/test/Transforms/LoopVectorize/tail-folding-counting-down.ll new file mode 100644 index 00000000000..2667bfe68f6 --- /dev/null +++ b/llvm/test/Transforms/LoopVectorize/tail-folding-counting-down.ll @@ -0,0 +1,42 @@ +; RUN: opt < %s -loop-vectorize -prefer-predicate-over-epilog -S | FileCheck %s + +; Check that when we can't predicate this loop that it is still vectorised (with +; an epilogue). +; TODO: the reason this can't be predicated is because a primary induction +; variable can't be found (not yet) for this counting down loop. But with that +; fixed, this should be able to be predicated. + +; CHECK-LABEL: vector.body: + +target datalayout = "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64" + +define dso_local void @foo(i8* noalias nocapture readonly %A, i8* noalias nocapture readonly %B, i8* noalias nocapture %C, i32 %N) { +entry: + %cmp6 = icmp eq i32 %N, 0 + br i1 %cmp6, label %while.end, label %while.body.preheader + +while.body.preheader: + br label %while.body + +while.body: + %N.addr.010 = phi i32 [ %dec, %while.body ], [ %N, %while.body.preheader ] + %C.addr.09 = phi i8* [ %incdec.ptr4, %while.body ], [ %C, %while.body.preheader ] + %B.addr.08 = phi i8* [ %incdec.ptr1, %while.body ], [ %B, %while.body.preheader ] + %A.addr.07 = phi i8* [ %incdec.ptr, %while.body ], [ %A, %while.body.preheader ] + %incdec.ptr = getelementptr inbounds i8, i8* %A.addr.07, i32 1 + %0 = load i8, i8* %A.addr.07, align 1 + %incdec.ptr1 = getelementptr inbounds i8, i8* %B.addr.08, i32 1 + %1 = load i8, i8* %B.addr.08, align 1 + %add = add i8 %1, %0 + %incdec.ptr4 = getelementptr inbounds i8, i8* %C.addr.09, i32 1 + store i8 %add, i8* %C.addr.09, align 1 + %dec = add i32 %N.addr.010, -1 + %cmp = icmp eq i32 %dec, 0 + br i1 %cmp, label %while.end.loopexit, label %while.body + +while.end.loopexit: + br label %while.end + +while.end: + ret void +} |