From: Duncan P. N. Exon Smith Date: Fri, 8 Dec 2017 22:42:43 +0000 (+0000) Subject: Revert part of "Cleanup some GraphTraits iteration code" X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d4ac46318e0dd3dd650a77bb3350d8172b83804c;p=llvm Revert part of "Cleanup some GraphTraits iteration code" This reverts part of r300656, which caused a regression in propagateMassToSuccessors by counting edges n^2 times, where n is the number of edges from the source basic block to the same successor basic block. The result was both incorrect and very slow to compute for large values of n (e.g. switches with multiple cases that go to the same basic block). Patch by Andrew Scheidecker! git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@320208 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Analysis/BlockFrequencyInfoImpl.h b/include/llvm/Analysis/BlockFrequencyInfoImpl.h index 228934cb301..24295a2569f 100644 --- a/include/llvm/Analysis/BlockFrequencyInfoImpl.h +++ b/include/llvm/Analysis/BlockFrequencyInfoImpl.h @@ -1314,9 +1314,12 @@ BlockFrequencyInfoImpl::propagateMassToSuccessors(LoopData *OuterLoop, 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; } diff --git a/test/Analysis/BlockFrequencyInfo/redundant_edges.ll b/test/Analysis/BlockFrequencyInfo/redundant_edges.ll new file mode 100644 index 00000000000..20ed1406c5a --- /dev/null +++ b/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 +}