[PATCH] D115109: [LV] Fix logic preventing tail-folding when an IV is used outside of the loop

Ricky Zhou via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 4 22:01:03 PST 2021


rickyz created this revision.
rickyz added a reviewer: mkuper.
Herald added subscribers: javed.absar, hiraditya.
rickyz requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

LoopVectorizationLegality::addInductionPhi() has a special case that
claims to prohibit IVs with loop-external uses when their SCEV relies on
predicates that may not hold outside of the loop. However, this logic
does not actually prevent vectorization when an induction PHI has
loop-external uses, as nothing ever checks for those external uses. This
special case on IVs isn't needed in the first place, as all of the
necessary predicates should have held when the value was computed.

Even though the special case fails to prohibit external IV uses, it can
still prevent the IV from being added to AllowedExit (the list of
variables that may be accessed outside of the loop). This can cause an
externally used IV to be hidden from the tail folding legality check in
LoopVectorizationLegality::prepareToFoldTailByMasking(), causing tail
folding to be inappropriately enabled. In PR52335, this led to
generating code with an incorrrect index computation.

Fix this by always adding IV PHIs to AllowedExit in
LoopVectorizationLegality::addInductionPhi.

This change also adds assertions that there are no externally-used IVs
when performing tail folding (and renames CountRoundDown to
VectorTripCount, since the vector trip count can be rounded up when
folding the tail).

Fixes PR52335.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115109

Files:
  llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
  llvm/test/Transforms/LoopVectorize/pr52335.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115109.391888.patch
Type: text/x-patch
Size: 11610 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211205/7cf85f5d/attachment.bin>


More information about the llvm-commits mailing list