[PATCH] D15559: [LoopUnrollRuntime] Do unroll when IV's setp is one or minus one

Michael Zolotukhin via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 21 16:12:18 PST 2015

mzolotukhin added a subscriber: mzolotukhin.

Comment at: lib/Transforms/Utils/LoopUnrollRuntime.cpp:325-331
@@ +324,9 @@
+                  SE->getSCEV(ExitCondICmp->getOperand(0)), L))) {
+        if (AR->isAffine() && AR->getOperand(1)->getSCEVType() == scConstant) {
+          if (const SCEVConstant *SCConst =
+                  cast<SCEVConstant>(AR->getOperand(1))) {
+            if (SCConst->getValue()->isOne() ||
+                SCConst->getValue()->isMinusOne())
+              AllowExpensiveTripCount = true;
+          }
+        }
There is a method `getStepRecurrence` in `AR`, which you might want to use here.

Also, I don't think that changing `AllowExpensiveTripCount` here is a good way to achieve what you try to achieve. Why (and where) is this tripcount considered expensive? To me it looks like we should rather fix those places to recognize cases like this as 'inexpensive'.


More information about the llvm-commits mailing list