This is an archive of the discontinued LLVM Phabricator instance.

[InlineCost] Improve debugging experience by adding print about initial inlining cost
ClosedPublic

Authored by yurai007 on Jun 12 2022, 5:14 AM.

Diff Detail

Event Timeline

yurai007 created this revision.Jun 12 2022, 5:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 12 2022, 5:14 AM
yurai007 requested review of this revision.Jun 12 2022, 5:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 12 2022, 5:14 AM

To put more context for this patch, while playing with LLVM Inliner I ended up with 2 very similar code snippets causing very different inlining decisions.
Looking at --debug-only=inline-cost output didn't help in figuring out what happened:

Analyzing call of kh_put_oligonucleotide... (caller:generate_Count_For_Oligonucleotide)
NumConstantArgs: 0
NumConstantOffsetPtrArgs: 2
NumAllocaArgs: 1
NumConstantPtrCmps: 0
NumConstantPtrDiffs: 0
NumInstructionsSimplified: 45
NumInstructions: 141
SROACostSavings: 25
SROACostSavingsLost: 0
LoadEliminationCost: 0
ContainsNoDuplicateCall: 0
Cost: -14490
Threshold: 325

remark: 'kh_put_oligonucleotide' inlined into 'generate_Count_For_Oligonucleotide' with (cost=-14490, threshold=325) at callsite generate_Count_For_Oligonucleotide:22:20; [-Rpass=inline]

Analyzing call of kh_put_oligonucleotide... (caller:generate_Count_For_Oligonucleotide)
NumConstantArgs: 0
NumConstantOffsetPtrArgs: 2
NumAllocaArgs: 1
NumConstantPtrCmps: 0
NumConstantPtrDiffs: 0
NumInstructionsSimplified: 45
NumInstructions: 141
SROACostSavings: 25
SROACostSavingsLost: 0
LoadEliminationCost: 0
ContainsNoDuplicateCall: 0
Cost: 510
Threshold: 325

remark: 'kh_put_oligonucleotide' not inlined into 'generate_Count_For_Oligonucleotide' because too costly to inline (cost=510, threshold=325) [-Rpass-missed=inline]

For both cases output is exactly same except final Cost value. It took me a while to realize that it's not unusual that major part of Cost is initial cost coming from various bonuses and penalties.
In my opinion it would be nice to emphasis this fact by printing initial cost value at the time when it's computed.
After such change I believe that debug output is more clear about what is source of final very low (or high in case of penalties) Cost value:

Analyzing call of kh_put_oligonucleotide... (caller:generate_Count_For_Oligonucleotide)
Initial cost: -15045
NumConstantArgs: 0
NumConstantOffsetPtrArgs: 2
NumAllocaArgs: 1
NumConstantPtrCmps: 0
NumConstantPtrDiffs: 0
NumInstructionsSimplified: 45
NumInstructions: 141
SROACostSavings: 25
SROACostSavingsLost: 0
LoadEliminationCost: 0
ContainsNoDuplicateCall: 0
Cost: -14490
Threshold: 325

remark: 'kh_put_oligonucleotide' inlined into 'generate_Count_For_Oligonucleotide' with (cost=-14490, threshold=325) at callsite generate_Count_For_Oligonucleotide:22:20; [-Rpass=inline]

Analyzing call of kh_put_oligonucleotide... (caller:generate_Count_For_Oligonucleotide)
Initial cost: -45
NumConstantArgs: 0
NumConstantOffsetPtrArgs: 2
NumAllocaArgs: 1
NumConstantPtrCmps: 0
NumConstantPtrDiffs: 0
NumInstructionsSimplified: 45
NumInstructions: 141
SROACostSavings: 25
SROACostSavingsLost: 0
LoadEliminationCost: 0
ContainsNoDuplicateCall: 0
Cost: 510
Threshold: 325

remark: 'kh_put_oligonucleotide' not inlined into 'generate_Count_For_Oligonucleotide' because too costly to inline (cost=510, threshold=325) [-Rpass-missed=inline]

Finally, although one may argue that with --print-instruction-comments=1 we can (kind of) deduce initial cost looking at cost before first analyzed instruction,
passing to Inliner --print-instruction-comments=1 produce much more verbose output (in comparison to normal debug one) and since it's dumped at the end on analysis
doesn't give clue when initial Cost value was set.

yurai007 added inline comments.Jun 12 2022, 5:21 AM
llvm/lib/Analysis/InlineCost.cpp
985

It's not camel cased (in opposite to stats like NumConstantArgs) to indicate that's just normal debug print like "Analyzing call..." one.

nikic accepted this revision.Jun 16 2022, 1:32 AM

Looks reasonable

This revision is now accepted and ready to land.Jun 16 2022, 1:32 AM

@nikic: Thanks for the review!

This revision was landed with ongoing or failed builds.Jun 24 2022, 7:29 AM
This revision was automatically updated to reflect the committed changes.