[PATCH] D115362: Compute estimated trip counts for multiple exit loops

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 8 10:30:25 PST 2021


reames created this revision.
reames added reviewers: anna, apilipenko, lebedev.ri, nikic, Whitney, hoy.
Herald added subscribers: zzheng, bollu, hiraditya, mcrosier.
reames requested review of this revision.
Herald added a project: LLVM.

This change allows us to estimate trip count from profile metadata for all multiple exit loops.  We still do the estimate only from the latch, but that's fine as it causes us to over estimate the trip count at worst.

Reviewing the uses of the API, all but one are cases where we restrict a loop transformation (unroll, and vectorize respectively) when we know the trip count is short enough.  So, as a result, the change makes these passes strictly less aggressive.  The test change illustrates a case where we'd previously have runtime unrolled a loop which ran fewer iterations than the unroll factor.  This is definitely unprofitable.

The one case where an upper bound on estimate trip count could drive a more aggressive transform is peeling, and I duplicated the logic being removed from the generic estimation there to keep it the same.  The resulting heuristic makes no sense and should probably be immediately removed, but we can do that in a separate change.

This was noticed when analyzing regressions on D113939 <https://reviews.llvm.org/D113939>.

I plan to come back and incorporate estimated trip counts from other exits, but that's a minor improvement which can follow separately.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D115362

Files:
  llvm/lib/Transforms/Utils/LoopPeel.cpp
  llvm/lib/Transforms/Utils/LoopUtils.cpp
  llvm/test/Transforms/LoopUnroll/runtime-multiexit-heuristic.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115362.392826.patch
Type: text/x-patch
Size: 14753 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211208/3440e75a/attachment.bin>


More information about the llvm-commits mailing list