[PATCH] D146383: [SimpleLoopUnswitch] Skip non-trivial unswitching of cold loop nests

Teresa Johnson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 19 08:54:29 PDT 2023


tejohnson created this revision.
tejohnson added reviewers: aeubanks, alexgatea.
Herald added subscribers: wenlei, hiraditya.
Herald added a project: All.
tejohnson requested review of this revision.
Herald added a project: LLVM.

This fixes a compile time issue due to guarding loop unswitching based
on whether the enclosing function is cold. That approach is very
inefficient in the case of large cold functions that contain numerous
loops, since the loop pass calls isFunctionColdInCallGraph once per
loop, and that function walks all BBs in the function (twice for Sample
PGO) looking for any non-cold blocks.

Originally, this code only checked if the current Loop's header was cold
(D129599 <https://reviews.llvm.org/D129599>). However, that apparently caused a slowdown on a SPEC
benchmark, and the example given was that of a cold inner loop nested in
a non-cold outer loop (see comments in D129599 <https://reviews.llvm.org/D129599>). The fix was to check if
the whole function is cold, done in D133275 <https://reviews.llvm.org/D133275>.

This is overkill, and we can simply check if the header of any loop in
the current loop's loop nest is non-cold (looking at both outer and
inner loops). This patch drops the compile time for a large module by
40% with this approach.

I also updated the test since it only had one cold loop in a non-cold
function, so that it instead had IR based off the example given in the
comments relating to the SPEC degradation in D129599 <https://reviews.llvm.org/D129599>. I confirmed that
the new version of the test fails with the original check done in
D129599 <https://reviews.llvm.org/D129599> of only the current loop's header coldness.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D146383

Files:
  llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
  llvm/test/Transforms/SimpleLoopUnswitch/PGO-nontrivial-unswitch2.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146383.506400.patch
Type: text/x-patch
Size: 16876 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230319/b8441acd/attachment.bin>


More information about the llvm-commits mailing list