[PATCH] D21720: Unroll for uncountable loops

Evgeny Stupachenko via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 10 13:30:22 PST 2017


evstupac added a comment.

> What do you mean by uncountable? How is it different from a loop with unknown trip count?

L is uncountble <=> isa<SCEVCouldNotCompute>(SE->getBackedgeTakenCount(L)) is true.
For unknown trip isa<SCEVCouldNotCompute>(SE->getBackedgeTakenCount(L)) is false.

> What's the difference between these two cases? I've gotten totally confused now.
> What is the case 3?

The cases that covered here:

1. Uncountable loops where previous value is reused (save one+ instruction for each value)
2. uncountable loops, that counts smth:

  while(smth) {
    body();
    n++;
  }

to:

  while(smth) {
    body();
    if (!smth) goto exit2;
    body();
    n+=2;
  }
  exit2:
  n++;
  loop exit:

Saves one+ "add" in the loop.

3. Uncountable loops switching states (not that frequent):

  while(smth) {
    body();
    s ^= n;
  }
  while(smth) {
    body();
    s = -s;
  }

Potentially saves a lot (as constant values could simplify several instructions).


Repository:
  rL LLVM

https://reviews.llvm.org/D21720





More information about the llvm-commits mailing list