This is an archive of the discontinued LLVM Phabricator instance.

[PGO] Fix insane counts due to nonreturn calls
ClosedPublic

Authored by xur on Dec 8 2016, 4:54 PM.

Details

Summary

Since we don't break BBs for function calls. We might get some insane counts
(wrap of unsigned) in the presence of noreturn calls.

This patch sets these counts to zero instead of the wrapped number.

Event Timeline

xur updated this revision to Diff 80848.Dec 8 2016, 4:54 PM
xur retitled this revision from to [PGO] Fix insane counts due to nonreturn calls.
xur updated this object.
xur added a reviewer: davidxl.
xur added subscribers: llvm-commits, eraman, xur.
davidxl added inline comments.Dec 8 2016, 5:31 PM
lib/Transforms/Instrumentation/PGOInstrumentation.cpp
888

Can you explain how this happens? For non return calls, should an edge be added from the call's BB to exit bb?

test/Transforms/PGOProfile/noreturncall.ll
9

exit is not used .

xur added a comment.Dec 8 2016, 9:45 PM

Using the test case as the example: exit() is called in bar0. The instrumentation is in bb2 (which calls bar0), bb4 and bb5.
bb2 is 21. bb4 is 0 and bb5 is 20. To make the edge flow balanced, we have to make edge 1-->3 as -1.

The real issue is that we don't have an edge from bar0 to the fake exit. We don't know if bar0 has a noreturn call.
The real solution is to split the BB with calls and and a fake edge.

We know this limitation when implementing IR PGO and we chose to tolerate this.

davidxl accepted this revision.Dec 9 2016, 4:00 PM
davidxl edited edge metadata.

lgtm

lib/Transforms/Instrumentation/PGOInstrumentation.cpp
889

Add a comment here that "If the one of the successor block can early terminate (no-return), we can end up with situation where out edge sum count is larger as the source BB's count is collected by a post-dominated block'.

This revision is now accepted and ready to land.Dec 9 2016, 4:00 PM
xur closed this revision.Dec 12 2016, 10:51 PM
xur marked 2 inline comments as done.