[all-commits] [llvm/llvm-project] 4979c9: [LV] Account for tripcount when calculation vector...

David Green via All-commits all-commits at lists.llvm.org
Thu May 6 04:37:16 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 4979c90458628c9463815d81c637f8787f72fff0
      https://github.com/llvm/llvm-project/commit/4979c90458628c9463815d81c637f8787f72fff0
  Author: David Green <david.green at arm.com>
  Date:   2021-05-06 (Thu, 06 May 2021)

  Changed paths:
    M llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
    A llvm/test/Transforms/LoopVectorize/ARM/mve-known-trip-count.ll

  Log Message:
  -----------
  [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




More information about the All-commits mailing list