[all-commits] [llvm/llvm-project] c4a096: Function Specialization Pass

sjoerdmeijer via All-commits all-commits at lists.llvm.org
Fri Jun 11 01:22:55 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: c4a0969b9c14acc795ae9e841b8289c3d36220b1
      https://github.com/llvm/llvm-project/commit/c4a0969b9c14acc795ae9e841b8289c3d36220b1
  Author: Sjoerd Meijer <sjoerd.meijer at arm.com>
  Date:   2021-06-11 (Fri, 11 Jun 2021)

  Changed paths:
    M llvm/include/llvm/InitializePasses.h
    M llvm/include/llvm/LinkAllPasses.h
    M llvm/include/llvm/Transforms/IPO.h
    M llvm/include/llvm/Transforms/IPO/SCCP.h
    M llvm/include/llvm/Transforms/Scalar/SCCP.h
    M llvm/include/llvm/Transforms/Utils/SCCPSolver.h
    M llvm/lib/Passes/PassBuilder.cpp
    M llvm/lib/Passes/PassRegistry.def
    M llvm/lib/Transforms/IPO/IPO.cpp
    M llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
    M llvm/lib/Transforms/IPO/SCCP.cpp
    M llvm/lib/Transforms/Scalar/CMakeLists.txt
    A llvm/lib/Transforms/Scalar/FunctionSpecialization.cpp
    M llvm/lib/Transforms/Scalar/SCCP.cpp
    M llvm/lib/Transforms/Utils/SCCPSolver.cpp
    A llvm/test/Transforms/FunctionSpecialization/function-specialization-recursive.ll
    A llvm/test/Transforms/FunctionSpecialization/function-specialization.ll
    A llvm/test/Transforms/FunctionSpecialization/function-specialization2.ll
    A llvm/test/Transforms/FunctionSpecialization/function-specialization3.ll
    A llvm/test/Transforms/FunctionSpecialization/function-specialization4.ll
    A llvm/test/Transforms/FunctionSpecialization/function-specialization5.ll

  Log Message:
  -----------
  Function Specialization Pass

This adds a function specialization pass to LLVM. Constant parameters
like function pointers and constant globals are propagated to the callee by
specializing the function.

This is a first version with a number of limitations:
- The pass is off by default, so needs to be enabled on the command line,
- It does not handle specialization of recursive functions,
- It does not yet handle constants and constant ranges,
- Only 1 argument per function is specialised,
- The cost-model could be further looked into, and perhaps related,
- We are not yet caching analysis results.

This is based on earlier work by Matthew Simpson (D36432) and Vinay Madhusudan.
More recently this was also discussed on the list, see:

https://lists.llvm.org/pipermail/llvm-dev/2021-March/149380.html.

The motivation for this work is that function specialisation often comes up as
a reason for performance differences of generated code between LLVM and GCC,
which has this enabled by default from optimisation level -O3 and up. And while
this certainly helps a few cpu benchmark cases, this also triggers in real
world codes and is thus a generally useful transformation to have in LLVM.

Function specialisation has great potential to increase compile-times and
code-size.  The summary from some investigations with this patch is:
- Compile-time increases for short compile jobs is high relatively, but the
  increase in absolute numbers still low.
- For longer compile-jobs, the extra compile time is around 1%, and very much
  in line with GCC.
- It is difficult to blame one thing for compile-time increases: it looks like
  everywhere a little bit more time is spent processing more functions and
  instructions.
- But the function specialisation pass itself is not very expensive; it doesn't
  show up very high in the profile of the optimisation passes.

The goal of this work is to reach parity with GCC which means that eventually
we would like to get this enabled by default. But first we would like to address
some of the limitations before that.

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




More information about the All-commits mailing list