[all-commits] [llvm/llvm-project] 83daa4: [LoopRotate] Add PrepareForLTO stage, avoid rotati...

Florian Hahn via All-commits all-commits at lists.llvm.org
Tue Jan 19 02:20:32 PST 2021


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 83daa49758a12d585fe2d9a64448e54d91bcfaff
      https://github.com/llvm/llvm-project/commit/83daa49758a12d585fe2d9a64448e54d91bcfaff
  Author: Florian Hahn <flo at fhahn.com>
  Date:   2021-01-19 (Tue, 19 Jan 2021)

  Changed paths:
    M llvm/include/llvm/Analysis/CodeMetrics.h
    M llvm/include/llvm/Transforms/Scalar.h
    M llvm/include/llvm/Transforms/Scalar/LoopRotation.h
    M llvm/include/llvm/Transforms/Utils/LoopRotationUtils.h
    M llvm/lib/Analysis/CodeMetrics.cpp
    M llvm/lib/Passes/PassBuilder.cpp
    M llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
    M llvm/lib/Transforms/Scalar/LoopRotation.cpp
    M llvm/lib/Transforms/Utils/LoopRotationUtils.cpp
    M llvm/test/Transforms/LoopRotate/call-prepare-for-lto.ll

  Log Message:
  -----------
  [LoopRotate] Add PrepareForLTO stage, avoid rotating with inline cands.

D84108 exposed a bad interaction between inlining and loop-rotation
during regular LTO, which is causing notable regressions in at least
CINT2006/473.astar.

The problem boils down to: we now rotate a loop just before the vectorizer
which requires duplicating a function call in the preheader when compiling
the individual files ('prepare for LTO'). But this then prevents further
inlining of the function during LTO.

This patch tries to resolve this issue by making LoopRotate more
conservative with respect to rotating loops that have inline-able calls
during the 'prepare for LTO' stage.

I think this change intuitively improves the current situation in
general. Loop-rotate tries hard to avoid creating headers that are 'too
big'. At the moment, it assumes all inlining already happened and the
cost of duplicating a call is equal to just doing the call. But with LTO,
inlining also happens during full LTO and it is possible that a previously
duplicated call is actually a huge function which gets inlined
during LTO.

>From the perspective of LV, not much should change overall. Most loops
calling user-provided functions won't get vectorized to start with
(unless we can infer that the function does not touch memory, has no
other side effects). If we do not inline the 'inline-able' call during
the LTO stage, we merely delayed loop-rotation & vectorization. If we
inline during LTO, chances should be very high that the inlined code is
itself vectorizable or the user call was not vectorizable to start with.

There could of course be scenarios where we inline a sufficiently large
function with code not profitable to vectorize, which would have be
vectorized earlier (by scalarzing the call). But even in that case,
there probably is no big performance impact, because it should be mostly
down to the cost-model to reject vectorization in that case. And then
the version with scalarized calls should also not be beneficial. In a way,
LV should have strictly more information after inlining and make more
accurate decisions (barring cost-model issues).

There is of course plenty of room for things to go wrong unexpectedly,
so we need to keep a close look at actual performance and address any
follow-up issues.

I took a look at the impact on statistics for
MultiSource/SPEC2000/SPEC2006. There are a few benchmarks with fewer
loops rotated, but no change to the number of loops vectorized.

Reviewed By: sanwou01

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




More information about the All-commits mailing list