[PATCH] D21048: [LV] Enable vectorization of loops where the IV has an external use

Michael Kuperstein via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 15 15:42:22 PDT 2016

mkuper added a comment.

In http://reviews.llvm.org/D21048#459394, @Ayal wrote:

> An alternative which I'm sure you thought of would be to fix/clean up such external users of IV's as a preparatory step (SimplifyIndVar?), eliminating them from the loop before starting to vectorize it. This may be a good thing to do early, for other "uses".

Yes, in fact, that's what I've started with, but abandoned that direction.
This is a question of cost modeling. SimplifyIndVar will already clean this up if it considers generating the end value cheap enough. And it seems like this decision should not depend on whether it expects vectorization in the future or not.

> It may be somewhat more efficient to traverse the LCSSA phi's at the single exit block that are fed by allowed-to-exit IV's in order to fix/clean them up, instead of traversing mostly irrelevant internal uses in search for out-of-loop ones.

I'm not sure it's much better. If the LCSSA phi uses the IV phi directly, it is. If it uses the value feeding into the IV phi, then we still need to find the IV this value belongs to. So, either have additional book-keeping, or go over the value's uses to find the phi.
If you think it may be significantly better, I can implement it, and see how it looks.

Comment at: llvm/trunk/lib/Transforms/Vectorize/LoopVectorize.cpp:3299-3300
@@ +3298,4 @@
+  // An external user of the penultimate value need to see EndValue - Step.
+  // The simplest way to get this is to recompute it from the constituent SCEVs,
+  // that is Start + (Step * (CRD - 1)).
+  for (User *U : OrigPhi->users()) {
Ayal wrote:
> need[s]
> "simplest" as it employs II.transform, which takes care of pointers as well; one could argue that doing EndValue - Step is simpler..
Yes, I want this to fire for pointer IVs as well, just enabling it step-by-step.



More information about the llvm-commits mailing list