This is an archive of the discontinued LLVM Phabricator instance.

[FuncSpec] Enable function specialize for a constant range of arguments
Needs ReviewPublic

Authored by Joe on Mar 3 2022, 7:18 AM.

Details

Reviewers
SjoerdMeijer
Summary

This will consider function specialization for candidate constants in a
constant range where the range represents all the possible arguments.

Currently, this will only happen when
-function-specialization-for-literal-constant is supplied.

Arguments from calls that are constant ranges themselves are still
unsupported.

I have a feeling I might be missing something here. Is there a reason why this wasn't already the case?

Tests affected (function-specialization.NumFuncSpecialized)

testbeforeafter
MultiSource/Applications/SPASS/SPASS.testNaN11.00
MultiSource/Applications/JM/ldecod/ldecod.testNaN3.00
MultiSource/Applications/oggenc/oggenc.test2.003.00

I tried measuring performance (Cycles/Instructions) with perf on x86, but there was too much noise in the results to gather anything meaningful.

Looking into the specialisations themselves, it often looks good. For some it introduces inlining opportunities. However, whether or not these were objectively good changes should be handled by the cost analysis. This change simply considers more opportunities.

Diff Detail

Event Timeline

Joe created this revision.Mar 3 2022, 7:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 3 2022, 7:18 AM
Joe requested review of this revision.Mar 3 2022, 7:18 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 3 2022, 7:18 AM

My understanding is that function specialization of such constant arguments is controlled by the option -function-specialization-for-literal-constant. That is disabled by default as it increases compilation times. I measured how it affects instruction count using perf when compiling the llvm test suite. It was generally neutral except for the benchmark SPASS which was regressed by 4%.

Joe added a comment.Mar 4 2022, 1:42 AM

My understanding is that function specialization of such constant arguments is controlled by the option -function-specialization-for-literal-constant. That is disabled by default as it increases compilation times. I measured how it affects instruction count using perf when compiling the llvm test suite. It was generally neutral except for the benchmark SPASS which was regressed by 4%.

Right I see. EnableSpecializationForLiteralConstant was an oversight for me. So what if EnableSpecializationForLiteralConstant is enabled, yet a function only takes literal constants, like in the unit test supplied. isArgumentInteresting would exit early due to the isOverdefined check. Should this be changed as is in this revision, but the change to getPossibleConstants be reverted?

Personally, I feel the design principle of current FuncSpec is to leave opportunities to IPSCCP if possible. I guess the main concern may be compilation time.
(Although I feel FuncSpec could cover IPSCCP.)

llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
683–690

My personal feeling is that FuncSpec might be able to replace IPSCCP completely if FuncSpec is ready enough. I tried to remove the whole check here in downstream and didn't see any regression in performance. (I didn't measure compile time though).

ormris removed a subscriber: ormris.Mar 7 2022, 9:56 AM
Joe updated this revision to Diff 416944.Mar 21 2022, 8:00 AM
Joe retitled this revision from [FuncSpec] Enable function specialize for a constant range of arguments. to [FuncSpec] Enable function specialize for a constant range of arguments.
Joe edited the summary of this revision. (Show Details)

Updated diff. Now a very small change.