diff --git a/llvm/lib/Transforms/Utils/PredicateInfo.cpp b/llvm/lib/Transforms/Utils/PredicateInfo.cpp index 9b239d9161e7f..67defef3f75f9 100644 --- a/llvm/lib/Transforms/Utils/PredicateInfo.cpp +++ b/llvm/lib/Transforms/Utils/PredicateInfo.cpp @@ -488,17 +488,19 @@ void PredicateInfoBuilder::buildPredicateInfo() { // Collect operands to rename from all conditional branch terminators, as well // as assume statements. SmallVector OpsToRename; - for (auto *DTN : depth_first(DT.getRootNode())) { - BasicBlock *BranchBB = DTN->getBlock(); - if (auto *BI = dyn_cast(BranchBB->getTerminator())) { + for (BasicBlock &BB : F) { + if (!DT.isReachableFromEntry(&BB)) + continue; + + if (auto *BI = dyn_cast(BB.getTerminator())) { if (!BI->isConditional()) continue; // Can't insert conditional information if they all go to the same place. if (BI->getSuccessor(0) == BI->getSuccessor(1)) continue; - processBranch(BI, BranchBB, OpsToRename); - } else if (auto *SI = dyn_cast(BranchBB->getTerminator())) { - processSwitch(SI, BranchBB, OpsToRename); + processBranch(BI, &BB, OpsToRename); + } else if (auto *SI = dyn_cast(BB.getTerminator())) { + processSwitch(SI, &BB, OpsToRename); } } for (auto &Assume : AC.assumptions()) {