This is an archive of the discontinued LLVM Phabricator instance.

[PGO] Add a threshold for number of critical edges in PGO
ClosedPublic

Authored by xur on Nov 1 2022, 11:54 AM.

Details

Summary

For some auto-generated sources, we have a huge number of critical edges (like from switch statements).
We have seen instance of 183777 critical edges in one function.
After we split the critical edges in PGO instrumentation/profile-use pass, the CFG is so large that we
have compiler time issues in downstream passes (like in machine CSE and block placement).
Here I add a threshold to skip PGO if the number of critical edges are too large.

The threshold is large enough so that it will not affect the majority of PGO compilation.

Also sync the logic for skipping instrumentation and profile-use. I think
this is the correct thing to do.

Diff Detail

Event Timeline

xur created this revision.Nov 1 2022, 11:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 1 2022, 11:54 AM
xur requested review of this revision.Nov 1 2022, 11:54 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 1 2022, 11:54 AM

Add a small test case (with small threshold)?

wenlei added a comment.Nov 1 2022, 1:32 PM

Why is number of critical edges (as opposed to IR size or number of blocks) a better indicator for function size related build speed issues?

xur added a comment.Nov 1 2022, 1:57 PM

Why is number of critical edges (as opposed to IR size or number of blocks) a better indicator for function size related build speed issues?

If we don't split the critical edge, the CFGs are the same for w/ and w/o PGO (for after PGO pass). So if the CFG is too big for some passes, PGO won't make it worse.

When we split the CFG, the CFGs for w/ and w/o PGO are different. The extra BBs added is roughly proportional to number of critical edges. So more critical edges means more discrepancy.
That's the main reason I choose to use number of critical edges as the threshold.

xur updated this revision to Diff 472431.Nov 1 2022, 3:25 PM

Add a test case, per David's suggestion.

wenlei added a comment.Nov 1 2022, 4:29 PM

Why is number of critical edges (as opposed to IR size or number of blocks) a better indicator for function size related build speed issues?

If we don't split the critical edge, the CFGs are the same for w/ and w/o PGO (for after PGO pass). So if the CFG is too big for some passes, PGO won't make it worse.

When we split the CFG, the CFGs for w/ and w/o PGO are different. The extra BBs added is roughly proportional to number of critical edges. So more critical edges means more discrepancy.
That's the main reason I choose to use number of critical edges as the threshold.

Makes sense if the goal is to avoid/limit extra build time incurred from PGO. Thanks for clarification.

davidxl accepted this revision.Nov 2 2022, 9:31 AM

lgtm

This revision is now accepted and ready to land.Nov 2 2022, 9:31 AM
This revision was landed with ongoing or failed builds.Nov 2 2022, 10:24 AM
This revision was automatically updated to reflect the committed changes.