Compute estimated trip counts for multiple exit loops
authorPhilip Reames <listmail@philipreames.com>
Thu, 9 Dec 2021 17:40:03 +0000 (09:40 -0800)
committerPhilip Reames <listmail@philipreames.com>
Thu, 9 Dec 2021 17:53:49 +0000 (09:53 -0800)
commit2d31b02517c0eacfa7edf62822cb7265e804e89c
tree9b66af455fd956caaeb731b90799d28ef4e3043b
parent06ca0a273308112c660dddf14c92fe14957bd468
Compute estimated trip counts for multiple exit loops

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.

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

Differential Revision: https://reviews.llvm.org/D115362
llvm/lib/Transforms/Utils/LoopPeel.cpp
llvm/lib/Transforms/Utils/LoopUtils.cpp
llvm/test/Transforms/LoopUnroll/runtime-multiexit-heuristic.ll