[PATCH] D19258: Loop vectorization with induction variable with non-constant step.

Elena Demikhovsky via llvm-commits llvm-commits at lists.llvm.org
Tue May 3 06:41:28 PDT 2016


delena added inline comments.

================
Comment at: ../lib/Transforms/Utils/LoopUtils.cpp:703
@@ -681,1 +702,3 @@
+        cast<ConstantInt>(StepValue)->isMinusOne())
       return B.CreateSub(StartValue, Index);
+    if (!isa<ConstantInt>(StepValue) || !cast<ConstantInt>(StepValue)->isOne())
----------------
hfinkel wrote:
> The logic here is now repeating things that SCEVExpander should already know how to do (plus SCEV might know about even more simplification rules). Try calculating the expression using SCEV and then expand that. This seems to be computing Start + Index*Step, so we can generate:
> 
>   const SCEV *S = SE->getAddExpr(SE->getSCEV(Start), SE->getMulExpr(SE->getSCEV(Index), Step);
>   return Exp.expandCodeFor(S, StartValue->getType(), &*B.GetInsertPoint());
> 
> If you use StartValue->getType() as I did above, this might just work for the pointer inductions too.
I tried to apply your proposal. The generated code is right but not always match the original. Some tests fail due to this replacement. It happens because getAddExpr() tries to combine all addends recursively. In some cases the result is better. But I saw one case at least, where the code became less optimal.


Repository:
  rL LLVM

http://reviews.llvm.org/D19258





More information about the llvm-commits mailing list