[PATCH] D66720: [LV] Fold tail by masking - handle reductions

Ayal Zaks via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 25 10:33:22 PDT 2019


Ayal created this revision.
Ayal added reviewers: hsaito, fhahn, dorit, dcaballe, reames, SjoerdMeijer.
Herald added subscribers: rogfer01, rkruppe, hiraditya.
Herald added a project: LLVM.

This addresses the "TODO: handle reductions when tail is folded by masking" left by D50480 <https://reviews.llvm.org/D50480>.

When folding the tail (scalar leftover iterations) by introducing an additional (masked) vector iteration at the end, first note that
the header phi of a reduction can remain intact - it takes care of "accumulating the partial sums" of a reduction across all iterations except for the last one. It is only this last iteration which now needs to accumulate these partial sums under a mask, effecting the live-out values. This can be accomplished by introducing a Select instruction, choosing between the last and penultimate (i.e., header phi) values of the partial sums.


https://reviews.llvm.org/D66720

Files:
  llvm/lib/Transforms/Vectorize/LoopVectorizationLegality.cpp
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
  llvm/lib/Transforms/Vectorize/VPlan.cpp
  llvm/test/Transforms/LoopVectorize/X86/tail_loop_folding.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66720.217047.patch
Type: text/x-patch
Size: 8475 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190825/e89f5179/attachment.bin>


More information about the llvm-commits mailing list