Index: include/llvm/Analysis/BlockFrequencyInfoImpl.h =================================================================== --- include/llvm/Analysis/BlockFrequencyInfoImpl.h +++ include/llvm/Analysis/BlockFrequencyInfoImpl.h @@ -1315,9 +1315,12 @@ return false; } else { const BlockT *BB = getBlock(Node); - for (const auto Succ : children(BB)) - if (!addToDist(Dist, OuterLoop, Node, getNode(Succ), - getWeightFromBranchProb(BPI->getEdgeProbability(BB, Succ)))) + for (auto SI = GraphTraits::child_begin(BB), + SE = GraphTraits::child_end(BB); + SI != SE; ++SI) + if (!addToDist( + Dist, OuterLoop, Node, getNode(*SI), + getWeightFromBranchProb(BPI->getEdgeProbability(BB, SI)))) // Irreducible backedge. return false; } Index: test/Analysis/BlockFrequencyInfo/redundant_edges.ll =================================================================== --- /dev/null +++ test/Analysis/BlockFrequencyInfo/redundant_edges.ll @@ -0,0 +1,22 @@ +; RUN: opt < %s -analyze -block-freq | FileCheck %s +; RUN: opt < %s -analyze -lazy-block-freq | FileCheck %s +; RUN: opt < %s -passes='print' -disable-output 2>&1 | FileCheck %s + +define void @test1() { +; CHECK-LABEL: Printing analysis {{.*}} for function 'test1': +; CHECK-NEXT: block-frequency-info: test1 +; CHECK-NEXT: entry: float = 1.0, int = [[ENTRY:[0-9]+]] +entry: + br label %loop + +; CHECK-NEXT: loop: float = 32.0 +loop: + switch i32 undef, label %loop [ + i32 0, label %return + i32 1, label %return + ] + +; CHECK-NEXT: return: float = 1.0 +return: + ret void +}