[PATCH] D93317: [LV] Vectorize (some) early and multiple exit loops

Ayal Zaks via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 22 14:56:23 PST 2020


Ayal accepted this revision.
Ayal added a comment.

This looks fine to me, thanks; would be good to get @fhahn approval too.

Wonder if a similar optimization may be applied to the loop unroller as well - discarding all exiting edges (keeping one in the latch only) from a single-latched "countable" loop, whose last iteration (or more) is peeled.



================
Comment at: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:7951
+    return EdgeMaskCache[Edge] = SrcMask;
+
   VPValue *EdgeMask = Plan->getOrAddVPValue(BI->getCondition());
----------------
Good catch and fix!


================
Comment at: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:1558
+    // iteration in scalar form.
+    if (!TheLoop->getExitingBlock() || !TheLoop->isRotatedForm())
+      return true;
----------------
reames wrote:
> Ayal wrote:
> > Checking that the only exit is the latch can be done (alternatively, literally) by
> > `if (TheLoop->getExitingBlock() == TheLoop->getLoopLatch())`
> I went ahead and switched since you seem to have a preference, but in general, these are not the same.  Consider an infinite loop with two latch blocks.  Such a loop can't reach here, but it requires context to know that.  The form of the check I used is context free.  
> 
> Doesn't really matter here, so I'll go with your preference.
Agreed, this form assumes there is a single latch, which is also implied by the comment, and can be asserted.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93317/new/

https://reviews.llvm.org/D93317



More information about the llvm-commits mailing list