[all-commits] [llvm/llvm-project] dfb40d: [SimpleLoopUnswitch] Skip non-trivial unswitching ...

Teresa Johnson via All-commits all-commits at lists.llvm.org
Mon Mar 20 10:15:12 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: dfb40d3fd7a261d7e3f697242df4680f1e6780ff
      https://github.com/llvm/llvm-project/commit/dfb40d3fd7a261d7e3f697242df4680f1e6780ff
  Author: Teresa Johnson <tejohnson at google.com>
  Date:   2023-03-20 (Mon, 20 Mar 2023)

  Changed paths:
    M llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
    M llvm/test/Transforms/SimpleLoopUnswitch/PGO-nontrivial-unswitch.ll
    M llvm/test/Transforms/SimpleLoopUnswitch/PGO-nontrivial-unswitch2.ll
    A llvm/test/Transforms/SimpleLoopUnswitch/PGO-nontrivial-unswitch3.ll

  Log Message:
  -----------
  [SimpleLoopUnswitch] Skip non-trivial unswitching of cold loop nests

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). 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). The fix was to check if
the whole function is cold, done in 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 PGO-nontrivial-unswitch2.ll 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. I confirmed that the new version of the test fails with the
original check done in D129599 of only the current loop's header
coldness.

Similarly updated test PGO-nontrivial-unswitch.ll to contain a cold loop
in a cold loop nest, and created PGO-nontrivial-unswitch3.ll to contain
a non-cold loop in a non-cold loop nest.

Differential Revision: https://reviews.llvm.org/D146383




More information about the All-commits mailing list