Question

When I perform the PGO optimization step (using LINK.EXE /LTCG:PGU), the Visual Studio 2010 linker complains:

Merging foo!1.pgc
'FOO_EDGE::get_input': Arc 2 --> 4 has negative count (-414343)
Expectation failed: f line 4241
'FOO_DELAY::set_delay': Block 18 outgoing counts differ from block count (-9 diff)
Expectation failed: f line 4261
Expectation failed: f line 4211
'FOO_DELAY::set_delay': Arc 12 --> 23 has negative count (-3)
Expectation failed: f line 4220
Generating code
907 of 4948 ( 18.33%) profiled functions will be compiled for speed
4948 of 4948 functions (100.0%) were optimized using profile data
42912225037 of 42912225037 instructions (100.0%) were optimized using profile data

What's causing these "expectation failures"? How should I address them? It seems like PGO is still optimizing the code, but I'm a little suspicious of the quality/completeness of the optimizations in the presence of these messages.

Was it helpful?

Solution

It seems that these errors occur when performing PGO-instrumented runs of multithreaded applications. They can be avoided by compiling (not linking) with the /PogoSafeMode flag on x64.

I didn't find the MSDN documentation on this flag particularly clear; the correct procedure for performing PGO on multithreaded code is:

  1. Compile with cl.exe /PogoSafeMode
  2. Link with link.exe /LTCG:PGI
  3. Execute your multithreaded profiling run(s)
  4. Re-link with link.exe /LTCG:PGO
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top