[PATCH] D102635: [LoopUnroll] Use tripcount from exiting header, if latch not exiting.

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 17 13:22:18 PDT 2021


reames requested changes to this revision.
reames added a comment.
This revision now requires changes to proceed.

This is semantically incorrect, and can not land.  There is an important distinction between a maximum trip count (which this code would be correct for), and an exact trip count (which is what this code appears to need).  Consider the case where the header exits after 20 iterations, and another non-latch exit exits after 10.  Fully unrolling by 20 would be incorrect.  (Since control flow is elided and we'd execute too many iterations.)

If you want to achieve the same effect correctly, you should update ScalarEvolution::getSmallConstantTripCount(L) to do what the block variant does, but with the getExitCount(L) version.  The change is straight forward, but you will need to audit callers to ensure they're not relying on the single exit block post-condition.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D102635/new/

https://reviews.llvm.org/D102635



More information about the llvm-commits mailing list