This is an archive of the discontinued LLVM Phabricator instance.

[FuncSpec] Enable specialization of literal constants.
ClosedPublic

Authored by labrinea on May 16 2023, 2:19 AM.

Details

Summary

To do so we have to tweak the cost model such that specialization does not trigger excessively.

Compile times -O3

benchmarknspecs beforenspecs afterinstrCnt delta %
ClamAV55+0.003
7zip1+0.006
tramp3d-v4-0.03
kimwitu++-0.015
sqlite3+0.034
mafft+0.022
lencod1+0.171
SPASS1+0.364
consumer-typeset1-0.007
Bullet11+0.015
geomean+0.056

Compile times LTO

benchmarknspecs beforenspecs afterinstrCnt delta %
ClamAV2+0.535
7zip+0.024
tramp3d-v4+0.022
kimwitu++-0.008
sqlite3+0.091
mafft-0.001
lencod6+0.205
SPASS31+0.032
consumer-typeset11-0.361
Bullet-0.01
geomean+0.053

Diff Detail

Event Timeline

labrinea created this revision.May 16 2023, 2:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 16 2023, 2:19 AM
labrinea requested review of this revision.May 16 2023, 2:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 16 2023, 2:19 AM
labrinea added inline comments.May 16 2023, 2:47 AM
llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
83–86

This is an emprirically made up number based on measurements mainly to keep the llvm test suite compile times low. Perhaps we could improve this in the future.

The code change looks trivial. So it looks good if the measured data (including compilation time and performance) don't have a regression.

llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
706–718

Can't we move this out of the loop simply?

739

What's the reason that we use / instead of - here?

labrinea updated this revision to Diff 523085.May 17 2023, 9:41 AM

Rebased on parent revision.

labrinea marked 2 inline comments as done.May 17 2023, 9:48 AM
labrinea added inline comments.
llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
706–718

It's explained in the comments. If we hoist this code we are eagerly asking for the BlockFrequencyAnalysis to run even if no specializations are found. I've checked and moving it regresses compilation times for benchmarks with no specializations.

739

Because we want the Bonus to be at least MinScore times higher than SpecCost. The delta was too aggressive heuristic. A ratio seems more sensible.

ChuanqiXu accepted this revision.May 18 2023, 12:30 AM
ChuanqiXu added inline comments.
llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
22–23

nit: It is better to have a paragraph for the cost model. This is not required now. We can add one after we feel it is relatively stable.

706–718

Got it. Thanks : )

739

I still don't understand it a lot. But maybe this is what heuristic model is.

This revision is now accepted and ready to land.May 18 2023, 12:30 AM
labrinea updated this revision to Diff 524887.May 23 2023, 2:29 PM
labrinea marked 2 inline comments as done.

rebase

labrinea edited the summary of this revision. (Show Details)May 24 2023, 9:17 AM
This revision was landed with ongoing or failed builds.May 25 2023, 2:05 AM
This revision was automatically updated to reflect the committed changes.
nikic added a subscriber: nikic.May 25 2023, 2:43 AM

What kind of run-time improvements does this give? The patch description mentions the compile-time regressions this causes, but not what improvements we get from it.

What kind of run-time improvements does this give? The patch description mentions the compile-time regressions this causes, but not what improvements we get from it.

We want this to enable vectorization of mc_chroma from 525.x264_r in SPEC INTrate 2017, but there's more work needed for that. This patch will let us create a specialized version where the loop boundaries are constant.

llvm/test/Transforms/FunctionSpecialization/function-specialization-minsize3.ll