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 SuccI = GraphTraits::child_begin(BB), + SuccE = GraphTraits::child_end(BB); + SuccI != SuccE; ++SuccI) + if (!addToDist( + Dist, OuterLoop, Node, getNode(*SuccI), + getWeightFromBranchProb(BPI->getEdgeProbability(BB, SuccI)))) // Irreducible backedge. return false; } Index: test/Analysis/BlockFrequencyInfo/redundant_edges.ll =================================================================== --- /dev/null +++ test/Analysis/BlockFrequencyInfo/redundant_edges.ll @@ -0,0 +1,35 @@ +; 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 i32 @test1(i32) { +; 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: + %i = phi i32 [%0, %entry], [%i.next, %blockEnd] + switch i32 %i, label %blockEnd [ + i32 0, label %return + i32 1, label %return + i32 2, label %return + i32 3, label %return + i32 4, label %return + i32 5, label %return + i32 6, label %return + i32 7, label %return + ] + +; CHECK-NEXT: blockEnd: float = 31.0 +blockEnd: + %i.next = add i32 %i, 1 + br label %loop + +; CHECK-NEXT: return: float = 1.0 +return: + %ret = phi i32 [ 0, %loop ], [ 0, %loop ], [ 0, %loop ], [ 0, %loop ], [ 0, %loop ], [ 0, %loop ], [ 0, %loop ], [ 0, %loop ] + ret i32 %ret +}