This is an archive of the discontinued LLVM Phabricator instance.

[BlockFrequencyInfo] Handling nested irreducible CFG with geometric series and top-down prorogation
Needs ReviewPublic

Authored by kula on Apr 12 2016, 9:23 PM.

Details

Summary

This patch implements the TODOs in BlockFrequencyInfoImpl.h.

  1. handle nested irreducible loop.
  2. true weight distribution among multi-heads of irreducible loop, instead of even split + adjustment by backedge later.
  3. Use geometric series instead of loop scale for mass iteration. loop scale are still used, but for the purpose of scaling down local mass below 1.0.
  4. normal code path for reducible loop is not affected.

This patch passes all regression test. Several test cases are changed accordingly. I've changed the @nonentry_header case in irreducible.ll to use
huge weight on the switch instruction to show that 'bottom' block should not be hot.

Method:

  1. for loop a, found all SCCs, create SCC loops and adjust nodes in its parent node list accordingly.
  2. In topological order, propagate mass on all SCCs where non-trivial SCCs incur resursion.
  3. compute start term of geometric series.
  4. for each header, compute its ratio of geometric series by propogation full mass starting from itself and other block hass empty mass. The cumulated backege mass is ratio.
  5. find the max ratio among headers.
  6. compute local scaled down mass for all headers with geometric series equation [a/(1-r)]. assume n is infinity. I've add a TODO in file to see if we should use [a*(1-r^n)/(1-r)].
  7. Propagate with header mass to other blocks in loop.

Diff Detail

Event Timeline

kula updated this revision to Diff 53516.Apr 12 2016, 9:23 PM
kula retitled this revision from to [BlockFrequencyInfo] Handling nested irreducible CFG with geometric series and top-down prorogation.
kula updated this object.
kula added reviewers: dexonsmith, dnovillo.
kula added a subscriber: llvm-commits.
kula added a comment.Apr 16 2016, 7:25 AM

gently ping.

dnovillo edited edge metadata.Apr 20 2016, 11:38 AM

I have started going over this patch, but my knowledge of this area is pretty spotty. I defer to Duncan for a better opinion on this.

kula added a comment.Apr 20 2016, 12:03 PM

Sounds good.

davidxl edited edge metadata.Apr 20 2016, 12:42 PM
davidxl added subscribers: davidxl, thanm.
kula updated this revision to Diff 54506.Apr 21 2016, 7:53 AM

Split out NFC. One bugfix.

thanm added a comment.May 9 2016, 10:39 AM

Hello,

Nice work, it was interesting to poke through this code and learn a bit about how block frequencies are calculated.

General remarks:

  • as w/ previous commenters I think it would be nice to have some concrete case from a real benchmark (spec or otherwise) where you can point to an improvement of some sort as a result of this change
  • the original version of the code makes reference to the idea of computing block frequencies using infinite geometric series (original BlockFrequencyInfoImpl.h lines 757, 786), but it is only in the test case (test/Analysis/BlockFrequencyInfo/irreducible.ll) where an actual example is provided along with its associated geometric series. Given that the new implementation is actually doing computing series start terms and ratios, I think it would make much more sense (from a readability perspective) to promote the comments/examples from the test case to the actual code itself.

I've posted more specific nits/comments inline on the Phab review page.

Thanks, Than

include/llvm/Analysis/BlockFrequencyInfoImpl.h
723–726

This comment seems to now be stale -- rewrite?

843

recurisvely => recursively

1192

size_t would be a better type for "i" (when I do a build with this patch I get a warning about signed/unsigned comparison)

1274

typo geometirc => geometric

dexonsmith resigned from this revision.Oct 6 2020, 3:48 PM