[PATCH] D12950: [SCEV] Teach isLoopBackedgeGuardedByCond to exploit trip counts.

Sanjoy Das via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 23 12:20:54 PDT 2015


sanjoy added inline comments.

================
Comment at: lib/Analysis/ScalarEvolution.cpp:7010
@@ +7009,3 @@
+  // predicate.
+  auto BECountIt = BackedgeTakenCounts.find(L);
+  if (BECountIt != BackedgeTakenCounts.end()) {
----------------
hfinkel wrote:
> It seems like we should add a comment in ScalarEvolution.h somewhere that isLoopBackedgeGuardedByCond will potentially-return more-accurate answers if you compute the look trip count first.
> 
> This seems unfortunate, but I suppose we can't force the trip-count computation here because we might infinitely recurse?
> 
> This seems unfortunate, but I suppose we can't force the trip-count
> computation here because we might infinitely recurse?

My motivation was to avoid burning excessive compile time computing
loop trip counts we'll never use.  But on second thought, this sounds
like a silly optimization -- even calling `getSCEV` will sometimes end
up causing the loop's trip count to be computed, so micro-optimizing
it away here does not make sense.  I'll change this to a direct call
to `getBackedgeTakenInfo`.

Btw, I don't think we'll end up with infinite recursion here.  If
`getBackedgeTakenInfo` ends up recursively calling this code, the
recursive call to `getBackedgeTakenInfo` should return "could not
compute" as the backedge trip for `Latch`, so we won't make the second
recursive call to `isImpliedCond`.

================
Comment at: lib/Analysis/ScalarEvolution.cpp:7019
@@ +7018,3 @@
+      const SCEV *LoopCounter =
+          getAddRecExpr(getZero(Ty), getOne(Ty), L, SCEV::FlagAnyWrap);
+      if (isImpliedCond(Pred, LHS, RHS, ICmpInst::ICMP_ULT, LoopCounter,
----------------
hfinkel wrote:
> Don't we know that SCEV::FlagNW | SCEV::FlagNUW here? Otherwise, it would not really be a trip count, would it?
> 
Yes, will fix.


http://reviews.llvm.org/D12950





More information about the llvm-commits mailing list