[PATCH] D119880: [FuncSpec] Support function specialization across multiple arguments.

Alexandros Lamprineas via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 15 12:10:25 PST 2022


labrinea created this revision.
labrinea added reviewers: SjoerdMeijer, dmgreen, fhahn, ChuanqiXu.
Herald added subscribers: snehasish, ormris, hiraditya.
labrinea requested review of this revision.
Herald added a project: LLVM.

This patch makes a significant change in the cost model as it no longer seems sensible to calculate the specialization gain per function argument, but rather as a whole. I've also lifted two arbitrary limitations around the specialization selection: the penalty in cost estimation for newly discovered functions, and the truncation of clones for a given function.

I think it's a pessimization to prevent a new specialization over a less profitable one, just because the latter was discovered first. Similarly, limiting the number of clones per function does not take profitability into account. That said, `MaxClonesThreshold` is now used only when the cost model is disregarded via -force-function-specialization. To control the code size increase I have added a new option `MinGainThreshold`. Deciding a default value for it seems tricky. Alternatively we could be sorting all the candidate specializations by gain, but that would incur higher compilation times, and also we would need an option to cotrol how many of them are we keeping. This seemed similar to `MinGainThreshold` so I chose that instead.

I have measured compilation times with the pass enabled/disabled by default using instruction count as the metric following these:
https://llvm-compile-time-tracker.com
https://github.com/nikic/llvm-compile-time-tracker

| testname         | % delta |
| ClamAV           | +0.541778070681293    |
| 7zip             | -0.103737291784568    |
| tramp3d-v4       | -0.00653090616083    |
| kimwitu++        | -0.022651269036529    |
| sqlite3          | +1.30109163228221    |
| mafft            | +0.397665430615558    |
| lencod           | +0.384376504149536    |
| SPASS            | +0.385081470780402    |
| Bullet           | -0.063843997423569    |
| consumer-typeset | +0.687729338003142    |


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119880

Files:
  llvm/include/llvm/Transforms/Utils/SCCPSolver.h
  llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
  llvm/lib/Transforms/Utils/SCCPSolver.cpp
  llvm/test/Transforms/FunctionSpecialization/function-specialization-constant-integers.ll
  llvm/test/Transforms/FunctionSpecialization/function-specialization-loop.ll
  llvm/test/Transforms/FunctionSpecialization/function-specialization-minsize3.ll
  llvm/test/Transforms/FunctionSpecialization/function-specialization.ll
  llvm/test/Transforms/FunctionSpecialization/function-specialization4.ll
  llvm/test/Transforms/FunctionSpecialization/remove-dead-recursive-function.ll
  llvm/test/Transforms/FunctionSpecialization/specialize-multiple-arguments.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119880.408995.patch
Type: text/x-patch
Size: 32540 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220215/56288ac0/attachment.bin>


More information about the llvm-commits mailing list