[LV] Account for tripcount when calculation vectorization profitability
authorDavid Green <david.green@arm.com>
Thu, 6 May 2021 11:36:46 +0000 (12:36 +0100)
committerDavid Green <david.green@arm.com>
Thu, 6 May 2021 11:36:46 +0000 (12:36 +0100)
commit4979c90458628c9463815d81c637f8787f72fff0
tree40d4ee10feea0a1fb26679dc077e26f6d2e7450e
parent5dd9f44c17ec0d8b6b88bb015560b3c566622fdc
[LV] Account for tripcount when calculation vectorization profitability

The loop vectorizer will currently assume a large trip count when
calculating which of several vectorization factors are more profitable.
That is often not a terrible assumption to make as small trip count
loops will usually have been fully unrolled. There are cases however
where we will try to vectorize them, and especially when folding the
tail by masking can incorrectly choose to vectorize loops that are not
beneficial, due to the folded tail rounding the iteration count up for
the vectorized loop.

The motivating example here has a trip count of 5, so either performs 5
scalar iterations or 2 vector iterations (with VF=4). At a high enough
trip count the vectorization becomes profitable, but the rounding up to
2 vector iterations vs only 5 scalar makes it unprofitable.

This adds an alternative cost calculation when we know the max trip
count and are folding tail by masking, rounding the iteration count up
to the correct number for the vector width. We still do not account for
anything like setup cost or the mixture of vector and scalar loops, but
this is at least an improvement in a few cases that we have had
reported.

Differential Revision: https://reviews.llvm.org/D101726
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
llvm/test/Transforms/LoopVectorize/ARM/mve-known-trip-count.ll [new file with mode: 0644]