Fix SCTC bug when two pred/succ BB are in a loop.

Summary: It's possible that two basic blocks being conidered for SCTC are in a loop in the CFG.  In this case a block that is both a predecessor and a successor may have been processed and marked invalid by a previous iteration of the SCTC loop. We should skip rewriting in this case.

(cherry picked from FBD5886721)
This commit is contained in:
Bill Nell 2017-09-21 15:45:39 -07:00 committed by Maksim Panchenko
parent 42f957bb75
commit aa05dc91c5
1 changed files with 10 additions and 0 deletions

View File

@ -619,6 +619,16 @@ uint64_t SimplifyConditionalTailCalls::fixTailCalls(BinaryContext &BC,
assert(Result && "internal error analyzing conditional branch");
assert(CondBranch && "conditional branch expected");
// It's possible that PredBB is also a successor to BB that may have
// been processed by a previous iteration of the SCTC loop, in which
// case it may have been marked invalid. We should skip rewriting in
// this case.
if (!PredBB->isValid()) {
assert(PredBB->isSuccessor(BB) &&
"PredBB should be valid if it is not a successor to BB");
continue;
}
// We don't want to reverse direction of the branch in new order
// without further profile analysis.
const bool DirectionFlag = CondSucc == BB ? IsForwardCTC : !IsForwardCTC;