This is an archive of the discontinued LLVM Phabricator instance.

[JumpThreading] Handle zero !prof branch_weights
ClosedPublic

Authored by yrouban on Jun 9 2020, 1:55 AM.

Details

Summary

Avoid division by zero in updatePredecessorProfileMetadata().
A test is added.

Diff Detail

Event Timeline

yrouban created this revision.Jun 9 2020, 1:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 9 2020, 1:55 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
yrouban marked an inline comment as done.Jun 10 2020, 5:59 AM

@kazu, @nikic, @yamauchi, @ebrevnov, @efriedma, please review this small fix.

llvm/lib/Transforms/Scalar/JumpThreading.cpp
260–265

Here BranchProbability::getBranchProbability(..., TrueWeight + FalseWeight) results in zero denominator if both TrueWeight and FalseWeight are zero.

hjyamauchi added inline comments.Jun 10 2020, 8:52 AM
llvm/lib/Transforms/Scalar/JumpThreading.cpp
219

Add a code comment that this is to avoid a division by zero below?

yrouban updated this revision to Diff 270032.Jun 10 2020, 10:02 PM
yrouban marked an inline comment as done.

added comment. Moved BP variable to its definition.

hjyamauchi accepted this revision.Jun 11 2020, 8:45 AM
This revision is now accepted and ready to land.Jun 11 2020, 8:45 AM
wenlei added a subscriber: wenlei.Jan 24 2022, 10:44 PM

Curious why the test case threading_prof3.ll didn't make it into the commit?

Curious why the test case threading_prof3.ll didn't make it into the commit?

Good catch! The test looks to be lost. I will push it tomorrow if you do not mind.

Curious why the test case threading_prof3.ll didn't make it into the commit?

Good catch! The test looks to be lost. I will push it tomorrow if you do not mind.

Sounds good, thanks!