[PATCH] D103255: [LV] Mark increment of main vector loop induction variable as NUW.

Ayal Zaks via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 9 15:03:26 PDT 2021


Ayal added inline comments.


================
Comment at: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp:3084
+      Builder.CreateAdd(Induction, Step, "index.next",
+                        /*NUW=*/!Cost->foldTailByMasking(), /*NSW=*/false);
   Induction->addIncoming(Start, L->getLoopPreheader());
----------------
Wrapping of %IV + %Step is related to wrapping of %End = %BackedgeTakenCount + 1, i.e., when %End wraps around to zero. In this case, minimum iteration checks indeed redirects away from the vector loop, unless the tail is folded.
However, it is conceivable to avoid this redirection and vectorize loops whose %End wraps around to zero, i.e., whose %IV + %Step also wraps; see D75746.

An alternative direction to ensure that %IV+%Step of vectorized loops don't wrap, even if their original %End does wrap and also when their tails are folded, is to control the vector loop with a **unit Step** %IV, whose upper bound is at most half of the original %End. If a vector %IV is also required, one can be constructed in parallel, or computed from %IV * %Step + <0,1,...,%Step-1>; eventually, LSR should know best to optimize them. Sounds reasonable?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D103255



More information about the llvm-commits mailing list