Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
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.
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. |
It's not camel cased (in opposite to stats like NumConstantArgs) to indicate that's just normal debug print like "Analyzing call..." one.