This is an archive of the discontinued LLVM Phabricator instance.

[LoopRotate] Add branch_weights metadata for rotated branch
Needs ReviewPublic

Authored by bin.cheng on Nov 6 2021, 4:50 AM.

Details

Reviewers
fhahn
mkazantsev
Summary

Hi,
When loop is rotated, the exit branch becomes a normal branch go to or skip the rotated loop. Since it's duplicated from loop exit branch, the result branch should have the same BPI as loop exit branch. However, the branch after rotation has nothing to do with the original loop and would very likely be predicated as 50/50% probability in BPI. This patch adds branch_weights metadata for it so it can be predicted with the same probability as loop exit branch. I also updated and looked into related tests and can confirm the change is expected.
Note that I searched around the code base but didn't see many use of branch_weight metadata, I assume it's mostly for use of profiled probability? So maybe it's inappropriate to use branch_weights metadata in this case, unfortunately, I didn't come up with any other better idea. Much appreciated for any comments that if I should handle the issue differently.

Thanks,
bin

Diff Detail

Event Timeline

bin.cheng created this revision.Nov 6 2021, 4:50 AM
bin.cheng requested review of this revision.Nov 6 2021, 4:50 AM
xbolva00 added inline comments.
llvm/test/Transforms/LoopRotate/callbr.ll
99

Check prof metadata?

CHECK: [[PROF]] = !{!"branch_weights", i32 ..., i32 ...}

Indeed, https://godbolt.org/z/cM8P49qxo, but it sounds like a BPI problem?

Indeed, https://godbolt.org/z/cM8P49qxo, but it sounds like a BPI problem?

Yes, it's a BPI problem, but it's difficult to handle in BPI without additional information. Please see my comment in D113345.

Thanks

llvm/test/Transforms/LoopRotate/callbr.ll
99

Check prof metadata?

CHECK: [[PROF]] = !{!"branch_weights", i32 ..., i32 ...}

Right, once confirm the idea is heading to right direction, I will add metadata check.

mkazantsev resigned from this revision.Mar 4 2022, 12:14 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 4 2022, 12:14 AM