This is an archive of the discontinued LLVM Phabricator instance.

Irreducible loop metadata for more accurate block frequency under PGO.
ClosedPublic

Authored by hjyamauchi on Oct 17 2017, 5:42 PM.

Details

Summary

Currently the block frequency analysis is an approximation for irreducible
loops.

The new irreducible loop metadata is used to annotate the irreducible loop
headers with their header weights based on the PGO profile (currently this is
approximated to be evenly weighted) and to help improve the accuracy of the
block frequency analysis for irreducible loops.

This patch is a basic support for this.

Event Timeline

hjyamauchi created this revision.Oct 17 2017, 5:42 PM
davidxl added inline comments.Oct 18 2017, 10:08 AM
include/llvm/Analysis/BlockFrequencyInfoImpl.h
1161

may be

if ( !(... HeaderWeight = ))

continue;
1166

Is this check needed?

1172

Can this share the same code with 'distributeIrrLoopHeaderMass' by making weights evenly distributed?

lib/IR/MDBuilder.cpp
203

loop_header_weight?

test/Analysis/BlockFrequencyInfo/irreducible_pgo.ll
5

Can this test case be minimized (eg. shrinking BB size ..) ?

hjyamauchi marked 4 inline comments as done.

Addressed comments.

hjyamauchi added inline comments.Oct 20 2017, 6:10 PM
include/llvm/Analysis/BlockFrequencyInfoImpl.h
1166

Yes, Dist.addLocal will has an assert against incoming zero value.

Changed the metadata name.
Added the metadata to the doc.

davidxl added inline comments.Oct 27 2017, 10:45 AM
include/llvm/Analysis/BlockFrequencyInfoImpl.h
1164

can just break here.

test/Transforms/PGOProfile/irreducible.ll
2

The profile generate tests do not seem to be relevant, can be removed.

hjyamauchi marked 2 inline comments as done.

Addressed comments.

include/llvm/Analysis/BlockFrequencyInfoImpl.h
1164

I tried it, turned out it needs to be a continue, because we still need the "IsIrrLoopHeader" (see line 1161 above) to be fully populated so that the PGO annotate pass can see which blocks are the headers and annotate accordingly (no headers have annotations before the PGO annotate pass, obviously.)

This revision is now accepted and ready to land.Oct 30 2017, 10:26 AM
hjyamauchi closed this revision.Nov 2 2017, 3:27 PM