[PATCH] D43876: [LoopUnroll] Peel off iterations if it makes conditions true/false.

Florian Hahn via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 13 02:47:06 PDT 2018


fhahn added inline comments.


================
Comment at: lib/Transforms/Utils/LoopUnrollPeel.cpp:194
+           SE.isKnownPredicate(Pred, IterVal, RightSCEV)) {
+      IterVal = SE.getAddExpr(
+          IterVal, cast<SCEVAddRecExpr>(LeftSCEV)->getStepRecurrence(SE));
----------------
mkazantsev wrote:
> fhahn wrote:
> > mkazantsev wrote:
> > > Step calculation can be hoisted out of this loop. I would also suggest bailing early if AR is not affine because adding a step of non-affine AddRec many times can produce really big and ugly SCEVs.
> > I've added a comment that makes it clearer I hope. The idea is to handle cases like below, where the condition is known to be false initially. Initially `i > 2` is not known, but the inverse `i  <= 2` is known.
> > 
> > ```
> > if (i > 2) {
> >   // do something
> > } else {
> >   // do something else
> > }
> > ```
> I see the point now, but you are using wrong function. If you look into `getSwappedPredicate`, it returns `<` for `>`, and what you need is called `getInversePredicate`.
Right, my bad, thank you very much :)


https://reviews.llvm.org/D43876





More information about the llvm-commits mailing list