[PATCH] D37425: LoopVectorize: MaxVF should not be larger than the loop trip count

Ayal Zaks via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 10 01:24:32 PDT 2017


Ayal added inline comments.


================
Comment at: llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp:6243
+  } else if (ConstTripCount && ConstTripCount < MaxVectorSize &&
+             isPowerOf2_32(ConstTripCount))
+    MaxVectorSize = ConstTripCount;
----------------
zvi wrote:
> Ayal wrote:
> > Better set MaxVectorSize to PowerOf2Floor(ConstTripCount), to also handle the case where ConstTripCount is not a power of 2.
> > 
> > Also, while we're at it: `computeFeasibleMaxVF()` is currently not required/documented to return a power of 2. We should either check that MaxVF is a power of 2 when checking `if (TC % MaxVF != 0)`, and then can simply set MaxVectorSize to ConstTripCount here. Otherwise we should document/assert that MaxVF is a power of 2.
> > Better set MaxVectorSize to PowerOf2Floor(ConstTripCount), to also handle the case where ConstTripCount is not a power of 2.
> What would there be a benefit of this suggestion  given that we currently bail out if there is a need for a tail-loop in the case of short-trip-count? Should we tie this with the work on vectorizing short trip count and allowing runtime checks/tail loops?
> 
> >Also, while we're at it: computeFeasibleMaxVF() is currently not required/documented to return a power of 2. We should either check that MaxVF is a power of 2 when checking if (TC % MaxVF != 0), and then can simply set MaxVectorSize to ConstTripCount here. Otherwise we should document/assert that MaxVF is a power of 2.
> It did not occur to me that MaxVF may not be a power of two. Can we label this as a follow-up work?
>>Better set MaxVectorSize to PowerOf2Floor(ConstTripCount), to also handle the case where ConstTripCount is not a power of 2.
> What would there be a benefit of this suggestion given that we currently bail out if there is a need for a tail-loop in the case of short-trip-count? Should we tie this with the work on vectorizing short trip count and allowing runtime checks/tail loops?

Well, your pr34468 shows where there would be a benefit, namely when TinyTripCount < ConstTripCount < MaxVL which allows runtime checks, i.e., does not bail-out if a tail-loop is needed.


> It did not occur to me that MaxVF may not be a power of two. Can we label this as a follow-up work?

Sure, suggest to simply document and assert that MaxVF is expected to be a power of two.


Repository:
  rL LLVM

https://reviews.llvm.org/D37425





More information about the llvm-commits mailing list