[PATCH] D127597: [InlineCost] Improve debugging experience by adding print about initial inlining cost

Dawid Jurczak via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 12 05:15:22 PDT 2022


yurai007 added a comment.

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.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D127597/new/

https://reviews.llvm.org/D127597



More information about the llvm-commits mailing list