This is an archive of the discontinued LLVM Phabricator instance.

[JumpThreading] Call eraseBlock when folding a conditional branch
ClosedPublic

Authored by kazu on Dec 3 2020, 2:13 PM.

Details

Summary

This patch teaches the jump threading pass to call BPI->eraseBlock
when it folds a conditional branch.

Without this patch, BranchProbabilityInfo could end up with stale edge
probabilities for the basic block containing the conditional branch --
one edge probability with less than 1.0 and the other for a removed
edge.

Diff Detail

Event Timeline

kazu created this revision.Dec 3 2020, 2:13 PM
kazu requested review of this revision.Dec 3 2020, 2:13 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 3 2020, 2:13 PM
kazu updated this revision to Diff 309386.Dec 3 2020, 3:24 PM

Added one more case.

yrouban accepted this revision.Dec 3 2020, 9:09 PM
yrouban added inline comments.
llvm/lib/Transforms/Scalar/JumpThreading.cpp
1097

should not we BPI->eraseBlock(BB) here? another patch?

1114

can we add an assertion on the return value of the ConstantFoldTerminator() call?

This revision is now accepted and ready to land.Dec 3 2020, 9:09 PM
kazu marked 2 inline comments as done.Dec 3 2020, 9:56 PM

Thanks for the review!

llvm/lib/Transforms/Scalar/JumpThreading.cpp
1097

Thank you for spotting. Yes, I'll take care of this in another patch.

1114

Good point. Let me address this in another patch after testing. Also, I'd like to make it easier to revert the assertion patch just in case.

This revision was automatically updated to reflect the committed changes.
kazu marked 2 inline comments as done.