[PATCH] D38948: [LV] Support efficient vectorization of an induction with redundant casts

Dorit Nuzman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 16 05:29:36 PDT 2017


dorit created this revision.
Herald added subscribers: hiraditya, sanjoy.

https://reviews.llvm.org/D30041 extended SCEVPredicateRewriter to improve handling of Phi nodes whose update chain involves casts; PSCEV can now build an AddRecurrence for some forms of such phi nodes, under the proper runtime overflow test. This means that we can identify such phi nodes as an induction, and the loop-vectorizer can now vectorize such inductions, however inefficiently. The vectorizer doesn't know that it can ignore the casts, and so it vectorizes them.

This patch records the casts in the InductionDescriptor, so that they could be marked to be ignored for cost calculation (we use vecValuesToIgnore for that) and ignored for vectorization/widening/scalarization (i.e. treated as TriviallyDead).

In addition to marking all these casts to be ignored, we also need to make sure that each cast is mapped to the right vector value in the vector loop body (be it a widened, vectorized, or scalarized induction). So whenever an induction phi is  mapped to a vector value (during vectorization/widening/scalarization), we also map the respective cast instruction (if exists) to that vector value.

Note: if the phi-update sequence of an induction involves more than one cast, then the above mapping to vector value is relevant only for the last cast of the sequence. (We also allow only the "last cast" to be used outside the induction update chain itself).

Lastly, we also record all these "last casts" in InductionCastsToIgnore; this is because some utilities, which need to query whether a Value is an Induction variable, may wish to be able to (quickly) identify that also a casted induction value behave like an Induction (e.g. for cost calculation, such as in getAddressAccessCost).

This is the last step in addressing PR30654.


https://reviews.llvm.org/D38948

Files:
  ../llvm/include/llvm/Analysis/ScalarEvolution.h
  ../llvm/include/llvm/Transforms/Utils/LoopUtils.h
  ../llvm/lib/Analysis/ScalarEvolution.cpp
  ../llvm/lib/Transforms/Utils/LoopUtils.cpp
  ../llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
  ../llvm/test/Transforms/LoopVectorize/vect-phiscev-sext-trunc.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38948.119140.patch
Type: text/x-patch
Size: 29608 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171016/cc7730d7/attachment.bin>


More information about the llvm-commits mailing list