[PATCH] [LoopVectorize] Induction variables: support arbitrary constant step

hfinkel at anl.gov hfinkel at anl.gov
Tue Jan 27 08:10:09 PST 2015

Comment at: lib/Transforms/Vectorize/LoopVectorize.cpp:722
@@ +721,3 @@
+    /// For pointer induction, returns StartValue[Index * StepValue].
+    Value *transform(IRBuilder<> &B, Value *Index) const {
+      switch (IK) {
aschwaighofer wrote:
> hfinkel wrote:
> > Given that we don't vectorize loops with wrap-around index spaces, as far as I know, we should be able to add nsw (or nuw or both) flags on these operations. Please do so when possible.
> Hal, I don't think this is safe. Consider the following example. The canonical induction variable does not wrap but the derived one does.
> int test(int *a) {
>   int r = 0;
>   uint64_t idx2=0;
>   for (uint64_t i = 0 ; i < UINT64_MAX; ++i) {
>     r+=a[idx2];
>     idx2 += 2;
>   }
>   return r;
> }
Agreed. But shouldn't we be able to get the nsw/nuw flags from the original scalar operation?

(If so, but this departs too far from the scope of this patch, I'm fine with adding a FIXME and leaving this for follow-up)



More information about the llvm-commits mailing list