[PATCH] D102437: [LV] NFCI: Move implementation of isScalarWithPredication to LoopVectorizationLegality

Sander de Smalen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 13 13:49:39 PDT 2021


sdesmalen created this revision.
Herald added subscribers: dexonsmith, hiraditya.
sdesmalen requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This patch moves [part of] the implementation of

  LoopVectorizationCostModel::isScalarWithPredication

->

  LoopVectorizationLegality::canVectorizeWithPredication.

The reason for this change is so that the legalization information can
be queried earlier on, before it has been finally decided whether tail
predication will be used. This is needed to avoid vectorization with
scalable vectors when there are e.g. predicated divides in the loop,
because we can't yet fall back on scalarization.

This patch also removes LoopVectorizationCostModel::blockNeedsPredication,
in favour of using LoopVectorizationLegality::blockNeedsPredication.

These functions together hide a cyclic dependence between the
choice of VF and whether or not to use tail-predication. i.e. To
determine the VF, the LV queries the cost-model, which in turn needs
to know whether the loop needs/uses predication in order to cost the
operations. Vice-versa, to know if the loop needs predication, the
LV needs to know the VF, so it can calculate if the trip-count is a
multiple of the VF.  For any VF that is smaller than the (power of 2)
MaxVF, we know that if the trip-count is divisible by MaxVF, then the
trip-count is also divisible by any other, smaller power-of-2 VF.
This means the LV can decide beforehand if tail predication is necessary,
but the calculation is pessimistic. We could improve the cost-query if we
know the trip-count is a multiple of the smaller VF (but not necessarily
the larger MaxVF). That will work for a follow-up patch, but this patch
already cleans up the interfaces in preparation.

The patch is intended to be NFC. It removes the VF argument to
`isScalarWithPredication`, which seems redundant and none of the tests
are affected, but this could be due to lack of test-coverage.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D102437

Files:
  llvm/include/llvm/IR/Instructions.h
  llvm/include/llvm/Transforms/Vectorize/LoopVectorizationLegality.h
  llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102437.345271.patch
Type: text/x-patch
Size: 11136 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210513/0bcad914/attachment.bin>


More information about the llvm-commits mailing list