[PATCH] D101726: [LV] Account for tripcount when calculation vectorization profitability

Dave Green via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun May 2 13:10:49 PDT 2021


dmgreen created this revision.
dmgreen added reviewers: sdesmalen, fhahn, RKSimon, bmahjour, spatel, SjoerdMeijer.
Herald added a subscriber: hiraditya.
dmgreen requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


https://reviews.llvm.org/D101726

Files:
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
  llvm/test/Transforms/LoopVectorize/ARM/mve-known-trip-count.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101726.342259.patch
Type: text/x-patch
Size: 19841 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210502/822cba9b/attachment.bin>


More information about the llvm-commits mailing list