[PATCH] D43876: [LoopUnroll] Peel off iterations if it makes conditions true/false.
Jun Bum Lim via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 9 10:45:37 PST 2018
junbuml added inline comments.
================
Comment at: lib/Transforms/Utils/LoopUnrollPeel.cpp:192
+ Pred = ICmpInst::getSwappedPredicate(Pred);
+ while (DesiredPeelCount < MaxPeelCount &&
+ SE.isKnownPredicate(Pred, IterVal, RightSCEV)) {
----------------
fhahn wrote:
> fhahn wrote:
> > junbuml wrote:
> > > Do we really need this loop. Isn't it possible to find the count using getMinusSCEV(RightSCEV, LeftSCEV->getStart()) as long as getMinusSCEV(RightSCEV, LeftSCEV->getStart()) is constant ?
> > Yes we could, but we would need some logic dealing with different predicates I think. That should not be too much work and I am happy to do it, unless there is existing infrastructure I might have missed.
> I had a closer look today. By using isKnownPredicate, we can also handle cases like the one below, where we compare 2 SCEVAddRecExprs, easily. Given that MaxPeelCount should be quite small and we only iterate at most MaxPeelCount times for each compare instruction, I am not sure if it's worth making things more complicated. It might be worth to add a "fast-path" for the case where we comparing a constant bound with a AddRecExpr with a known integer constant. What do you think?
>
>
>
> ```
> for.body.lr.ph:
> br label %for.body
>
> for.body:
> %i.05 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ]
> %j = phi i32 [ 2, %for.body.lr.ph ], [ %j.inc, %for.inc ]
> %cmp1 = icmp ult i32 %i.05, %j
> br i1 %cmp1, label %if.then, label %for.inc
>
> if.then:
> call void @f1()
> br label %for.inc
>
> for.inc:
> %inc = add nsw i32 %i.05, 2
> %j.inc = add nsw i32 %j, 1
> %cmp = icmp slt i32 %inc, %k
> br i1 %cmp, label %for.body, label %for.end
>
> for.end:
> ret void
> ```
Based on that MaxPeelCount is a small constant, I don't see any big burden on it. fast-path sounds good to me.
https://reviews.llvm.org/D43876
More information about the llvm-commits
mailing list