[PATCH] D45191: [LoopReroll] Rewrite induction variable rewriting.

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 24 13:37:04 PDT 2018


efriedma added a comment.

> I am probably missing something, but maybe we could avoid the overflow by doing the re-writing of the induction variables/exit conditions closer to the original range for the induction variables?

The fundamental problem is that the rerolled loop could have a trip count that doesn't fit into a single register, even if the original loop's trip count does fit (e.g. on a 32-bit target, the original loop has a trip count 2^31, we reroll by a factor of four, and the new loop has a trip count of 2^33).  So handling overflow correctly in general requires some extra code in the rerolled loop.

In some cases, we could probably prove the trip count can't actually overflow.  And in the cases where it could overflow, there are a few ways to handle it: we could emit an induction variable with an illegal type, or we could emit a nested loop.  I'm not sure what the best approach is.



================
Comment at: lib/Transforms/Scalar/LoopRerollPass.cpp:1415
+    const SCEVAddRecExpr *IVSCEV =
+        cast<SCEVAddRecExpr>(SE->getSCEV(DRS.BaseInst));
+    StartExprs.push_back(IVSCEV->getStart());
----------------
javed.absar wrote:
> Should probably use dyn_cast if we cant be 100% it will be SCEVAddRecExpr.
It will always be a SCEVAddRecExpr; we check earlier.  (This is a fundamental part of proving that the rerolled loop is equivalent to the original loop.)


Repository:
  rL LLVM

https://reviews.llvm.org/D45191





More information about the llvm-commits mailing list