[FuncSpec] Do not overestimate the specialization bonus for users inside loops.
authorAlexandros Lamprineas <alexandros.lamprineas@arm.com>
Tue, 25 Oct 2022 15:45:18 +0000 (16:45 +0100)
committerAlexandros Lamprineas <alexandros.lamprineas@arm.com>
Thu, 27 Oct 2022 14:26:11 +0000 (15:26 +0100)
commitdbeaf6baa2ad12112e7092f5814396f444733958
tree5dacebac2eb267de369a75742a34899e0e5713fe
parentd2d23795cac9ecfae9f5f18be05e4211d4c0cac2
[FuncSpec] Do not overestimate the specialization bonus for users inside loops.

When calculating the specialization bonus for a given function argument,
we recursively traverse the chain of (certain) users, accumulating the
instruction costs. Then we exponentially increase the bonus to account
for loop nests. This is problematic for two reasons: (a) the users might
not themselves be inside the loop nest, (b) if they are we are accounting
for it multiple times. Instead we should be adjusting the bonus before
traversing the user chain.

This reduces the instruction count for CTMark (newPM-O3) when Function
Specialization is enabled without actually reducing the amount of
specializations performed (geomean: -0.001% non-LTO, -0.406% LTO).

Differential Revision: https://reviews.llvm.org/D136692
llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
llvm/test/Transforms/FunctionSpecialization/function-specialization-loop.ll