Index: llvm/lib/Transforms/Scalar/JumpThreading.cpp =================================================================== --- llvm/lib/Transforms/Scalar/JumpThreading.cpp +++ llvm/lib/Transforms/Scalar/JumpThreading.cpp @@ -2237,12 +2237,8 @@ CloneInstructions(PredBB->begin(), PredBB->end(), NewBB, PredPredBB); // Copy the edge probabilities from PredBB to NewBB. - if (HasProfileData) { - SmallVector Probs; - for (BasicBlock *Succ : successors(PredBB)) - Probs.push_back(BPI->getEdgeProbability(PredBB, Succ)); - BPI->setEdgeProbability(NewBB, Probs); - } + if (HasProfileData) + BPI->copyEdgeProbabilities(PredBB, NewBB); // Update the terminator of PredPredBB to jump to NewBB instead of PredBB. // This eliminates predecessors from PredPredBB, which requires us to simplify @@ -2672,6 +2668,8 @@ // Remove the unconditional branch at the end of the PredBB block. OldPredBranch->eraseFromParent(); + if (HasProfileData) + BPI->copyEdgeProbabilities(BB, PredBB); DTU->applyUpdatesPermissive(Updates); ++NumDupes;