HomePhabricator

Function Specialization Pass

Authored by SjoerdMeijer on May 4 2021, 7:12 AM.

Description

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

Details

Committed
SjoerdMeijerJun 11 2021, 1:11 AM
Differential Revision
D93838: [SCCP] Add Function Specialization pass
Parents
rG22f194909ae2: Revert "[Driver] Support libc++ in MSVC"
Branches
Unknown
Tags
Unknown