This is an archive of the discontinued LLVM Phabricator instance.

[WIP][BPI] `calcEstimatedHeuristics()`: symmetrically with loop exiting edge, scale loop enter edge weight by trip count
AbandonedPublic

Authored by lebedev.ri on Nov 6 2021, 6:06 AM.

Details

Summary

I don't really know this area of LLVM, and probably not equipped to drive this the end.
This is motivated by D113342, but implemented in a more general manner.

Diff Detail

Event Timeline

lebedev.ri created this revision.Nov 6 2021, 6:06 AM
lebedev.ri updated this revision to Diff 385283.Nov 6 2021, 8:53 AM

Fix one more test.

bin.cheng added inline comments.Nov 6 2021, 8:15 PM
llvm/lib/Analysis/BranchProbabilityInfo.cpp
850

Please correct me if I understand the idea incorrectly.
The problem at this point is that we don't know if the entering edge is duplicated from loop exit branch from LoopRotate. The edge could be from source code or other transformations, in this case, we don't really know the probability taking or skipping the guarded loop. For example, GCC has a heuristics saying that guarded inner loop in loop nest usually is not likely to be executed.

lkail added a subscriber: lkail.Nov 6 2021, 8:22 PM
lebedev.ri updated this revision to Diff 385331.Nov 7 2021, 2:05 AM

Only do so for loops in rotated form.

It seems that the new heuristic is applied not only to loops in rotated form. For example "test_cold_loop" or "test13".
In general we should decrease probability to take particular back edge proportionally to number of added exits. For example if number of exits equal to number of predicted iterations then each particular exit should be 50/50. But this is not supported yet anyway..

bin.cheng added inline comments.Nov 8 2021, 1:03 AM
llvm/lib/Analysis/BranchProbabilityInfo.cpp
851

IMHO isRotatedForm check is not enough because it only checks "form". For example, a user written do-while loop under some irrelevant guard condition. Is it possible to also check if we are checking on induction variable of SuccLoop? I guess this covers most cases with minimum false positive.

lebedev.ri abandoned this revision.Jan 17 2022, 2:37 PM