llvm-project
13d91555 - [LoopUnroll] Fix freqs for unconditional latches: N<=2 (#179520)

Commit
7 days ago
[LoopUnroll] Fix freqs for unconditional latches: N<=2 (#179520) As another step in issue #135812, this patch fixes block frequencies when LoopUnroll converts a conditional latch in an unrolled loop iteration to unconditional. It thus includes complete loop unrolling (the conditional backedge becomes an unconditional loop exit), which might be applied to the original loop or to its remainder loop. As explained in detail in the header comments on the fixProbContradiction function that this patch introduces, these conversions mean LoopUnroll has proven that the original uniform latch probability is incorrect for the original loop iterations associated with the converted latches. However, LoopUnroll often is able to perform these corrections for only some iterations, leaving other iterations with the original latch probability, and thus corrupting the aggregate effect on the total frequency of the original loop body. This patch ensures that the total frequency of the original loop body, summed across all its occurrences in the unrolled loop after the aforementioned conversions, is the same as in the original loop. Unlike other patches in this series, this patch cannot derive the required latch probabilities directly from the original uniform latch probability because it has been proven incorrect for some original loop iterations. Instead, this patch computes entirely new probabilities for the remaining N conditional latches in the unrolled loop. This patch only handles N <= 2, for which it uses simple formulas to compute a single uniform probability across the latches. Future patches will handle N > 2. This patch series does not consider the presence of non-latch loop exits, and I do not have a solid plan for that case. See fixme comments this patch introduces. This patch depends on PR #182403 and PR #191008.
Author
Parents
Loading