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

Hal Finkel via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 29 08:09:29 PDT 2016


hfinkel added inline comments.

================
Comment at: ../lib/Transforms/Utils/LoopUtils.cpp:661
@@ -659,1 +660,3 @@
+
+  // Check Start Value
   assert(StartValue && "StartValue is null");
----------------
Comments should be complete sentences and end with a period.

================
Comment at: ../lib/Transforms/Utils/LoopUtils.cpp:668
@@ +667,3 @@
+
+  // Check Step
+  assert((!getConstIntStepValue() || !getConstIntStepValue()->isZero()) &&
----------------
See above.

================
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())
----------------
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.


Repository:
  rL LLVM

http://reviews.llvm.org/D19258





More information about the llvm-commits mailing list