Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Debug info not maintained in AutoFDO #25481

Open Quuxplusone opened 8 years ago

Quuxplusone commented 8 years ago
Bugzilla Link PR25482
Status REOPENED
Importance P normal
Reported by Dehao Chen (danielcdh@gmail.com)
Reported on 2015-11-10 16:54:56 -0800
Last modified on 2017-01-09 16:02:01 -0800
Version trunk
Hardware PC Linux
CC davidxl@google.com, dblaikie@gmail.com, ditaliano@apple.com, dnovillo@google.com, llvm-bugs@lists.llvm.org
Fixed by commit(s)
Attachments c.cc (117 bytes, text/x-c++src)
c.txt (60 bytes, text/plain)
Blocks PR31268
Blocked by
See also
If -fprofile-sample-use is specified, clang will set
CodeGenOptions::LocTrackingOnly and make the FE emit debug info. However, as
the debug info is not emitted in the final binary, there are several issues
that prevents the debug info from being updated correctly:

* The discriminator will not be applied due to !hasDebugInfo(F) check
* Inline stack is not maintained during function inlining

In general, we need frontend to pass down a parameter to let backend
optimization know that debug info still needs to be maintained.
Quuxplusone commented 8 years ago
(In reply to comment #0)
> If -fprofile-sample-use is specified, clang will set
> CodeGenOptions::LocTrackingOnly and make the FE emit debug info. However, as
> the debug info is not emitted in the final binary, there are several issues
> that prevents the debug info from being updated correctly:
>
> * The discriminator will not be applied due to !hasDebugInfo(F) check
> * Inline stack is not maintained during function inlining
>
> In general, we need frontend to pass down a parameter to let backend
> optimization know that debug info still needs to be maintained.

It sounds like this can be one of the main source of performance loss for
sample fdo.
Quuxplusone commented 8 years ago
(In reply to comment #1)
> (In reply to comment #0)
> > If -fprofile-sample-use is specified, clang will set
> > CodeGenOptions::LocTrackingOnly and make the FE emit debug info. However, as
> > the debug info is not emitted in the final binary, there are several issues
> > that prevents the debug info from being updated correctly:
> >
> > * The discriminator will not be applied due to !hasDebugInfo(F) check
> > * Inline stack is not maintained during function inlining
> >
> > In general, we need frontend to pass down a parameter to let backend
> > optimization know that debug info still needs to be maintained.
>
> It sounds like this can be one of the main source of performance loss for
> sample fdo.

Yes.  The testing I've been doing so far has used -g in both the gen and the
use binaries, however.

The trick of not emitting the debug info marker is used to get the code
generator not to emit debug info.  The bug is using the same hasDebugInfo()
function in the discriminator assignment.  That pass should dig past that.
I'll take a look.
Quuxplusone commented 8 years ago

Fixed with http://llvm.org/viewvc/llvm-project?rev=252763&view=rev

Quuxplusone commented 8 years ago

Attached c.cc (117 bytes, text/x-c++src): source file

Quuxplusone commented 8 years ago

Attached c.txt (60 bytes, text/plain): sample profile in text format

Quuxplusone commented 8 years ago
The inline stack is still not maintained correctly in this bug. Here is how to
reproduce:

#bin/clang++ -c -fprofile-sample-use=c.txt -O2 -save-temps -v c.cc
#bin/opt -sample-profile -sample-profile-file=c.txt c.bc -S|bin/opt -analyze -
branch-prob
Printing analysis 'Branch Probability Analysis' for function '_Z3foov':
---- Branch Probabilities ----
  edge entry -> if.then.i probability is 0x50000000 / 0x80000000 = 62.50%
  edge entry -> if.else.i probability is 0x30000000 / 0x80000000 = 37.50%
  edge if.then.i -> _ZL3barv.exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
  edge if.else.i -> _ZL3barv.exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
Printing analysis 'Branch Probability Analysis' for function '_ZL3barv':
---- Branch Probabilities ----
  edge entry -> if.then probability is 0x50000000 / 0x80000000 = 62.50%
  edge entry -> if.else probability is 0x30000000 / 0x80000000 = 37.50%
  edge if.then -> if.end probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
  edge if.else -> if.end probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]

#bin/clang++ -c -fprofile-sample-use=c.txt -O2 -save-temps -v c.cc -g
#bin/opt -sample-profile -sample-profile-file=c.txt c.bc -S|bin/opt -analyze -
branch-prob
Printing analysis 'Branch Probability Analysis' for function '_Z3foov':
---- Branch Probabilities ----
  edge entry -> if.then.i probability is 0x00000000 / 0x80000000 = 0.00%
  edge entry -> if.else.i probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
  edge if.then.i -> _ZL3barv.exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
  edge if.else.i -> _ZL3barv.exit probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
Printing analysis 'Branch Probability Analysis' for function '_ZL3barv':
---- Branch Probabilities ----
  edge entry -> if.then probability is 0x50000000 / 0x80000000 = 62.50%
  edge entry -> if.else probability is 0x30000000 / 0x80000000 = 37.50%
  edge if.then -> if.end probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
  edge if.else -> if.end probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]

With and without "-g", branch-probability gives different branch probability
estimation for _Z3foov.
Quuxplusone commented 8 years ago

The implementation of -fprofile-sample-use tells the driver to enable LOC tracking, we also need to track inline activity. For reference, the original patch is http://reviews.llvm.org/D5888.

To track inlines, we'll need the debug code generator to also emit inline information.