From aa05dc91c51d5b9acac3cf1c0f43ef386fd44e9f Mon Sep 17 00:00:00 2001 From: Bill Nell Date: Thu, 21 Sep 2017 15:45:39 -0700 Subject: [PATCH] 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) --- bolt/Passes/BinaryPasses.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/bolt/Passes/BinaryPasses.cpp b/bolt/Passes/BinaryPasses.cpp index 559e979b38f5..302152d121ae 100644 --- a/bolt/Passes/BinaryPasses.cpp +++ b/bolt/Passes/BinaryPasses.cpp @@ -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;