llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.18k stars 11.63k forks source link

Debug info not maintained in AutoFDO #25856

Open llvmbot opened 8 years ago

llvmbot commented 8 years ago
Bugzilla Link 25482
Version trunk
OS Linux
Blocks llvm/llvm-project#30616
Reporter LLVM Bugzilla Contributor
CC @vns-mn,@dwblaikie,@dnovillo

Extended Description

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:

In general, we need frontend to pass down a parameter to let backend optimization know that debug info still needs to be maintained.

adrian-prantl commented 2 years ago

mentioned in issue llvm/llvm-project#30616

dnovillo 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.

llvmbot 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.

llvmbot commented 8 years ago

sample profile in text format

llvmbot commented 8 years ago

source file

dnovillo commented 8 years ago

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

dnovillo commented 8 years ago

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.

david-xl commented 8 years ago

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.

llvmbot commented 8 years ago

assigned to @dnovillo