[PATCH] D76838: [LV] WIP: Tail-folding counting down loops
Sjoerd Meijer via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 26 05:23:16 PDT 2020
SjoerdMeijer created this revision.
SjoerdMeijer added reviewers: Ayal, fhahn, samparker, hsaito.
Herald added subscribers: danielkiss, rkruppe, hiraditya, kristof.beyls.
This is a work-in-progress patch to support tail-folding for counting down loops, i.e. loops with a constant step value of -1.
The reason why tail-folding isn't triggered for these cases, is because induction variables with a -1 step value are not considered candidates as a primary induction variable. A minimal motivating example is as simple as this:
void f (char *a, char *b, char *c, int N) {
while (N-- > 0)
*c++ = *a++ + *b++;
}
This will (of course) be vectorised, but when tail-folding is requested quite early in the vectorisation pipeline, it hasn't discovered the primary induction variable, inhibiting tail-folding for counting down loops.
My motivating example is:
test/Transforms/LoopVectorize/ARM/tail-folding-counting-down.ll
To make all differences explicit and visible, I have first locally regenerated all output for this example without this patch applied. This patch shows the differences compared to this local diff.
I am requesting early feedback on this patch because I need to deal with a handful of tests that need some special care. Motiving example for this is:
test/Transforms/LoopVectorize/reverse_induction.ll
This needs the offset calculation as I have also commented and highlighted in that test:
[[OFFSET_IDX:%.*]] = sub i64 [[STARTVAL]], [[INDEX]]
And to maintain this, I need to recognise the -1 step value in `CreateScalarIV()`, which I think this makes sense when we need a scalar IV and we're counting down, but this is what I wanted to check with you. As I said, this is work-progress, but if the approach is right, then I will clean up the code and modify some more tests.
https://reviews.llvm.org/D76838
Files:
llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/test/Transforms/LoopVectorize/ARM/tail-folding-counting-down.ll
llvm/test/Transforms/LoopVectorize/reverse_induction.ll
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76838.252802.patch
Type: text/x-patch
Size: 42888 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200326/ce37e9dd/attachment.bin>
More information about the llvm-commits
mailing list