File tree 2 files changed +52
-4
lines changed
lib/Transforms/Instrumentation
test/Transforms/Coroutines
2 files changed +52
-4
lines changed Original file line number Diff line number Diff line change @@ -1658,11 +1658,17 @@ void PGOUseFunc::setBranchWeights() {
1658
1658
continue ;
1659
1659
1660
1660
// We have a non-zero Branch BB.
1661
- unsigned Size = BBCountInfo.OutEdges .size ();
1662
- SmallVector<uint64_t , 2 > EdgeCounts (Size , 0 );
1661
+
1662
+ // SuccessorCount can be greater than OutEdgesCount, because
1663
+ // removed edges don't appear in OutEdges.
1664
+ unsigned OutEdgesCount = BBCountInfo.OutEdges .size ();
1665
+ unsigned SuccessorCount = BB.getTerminator ()->getNumSuccessors ();
1666
+ assert (OutEdgesCount <= SuccessorCount);
1667
+
1668
+ SmallVector<uint64_t , 2 > EdgeCounts (SuccessorCount, 0 );
1663
1669
uint64_t MaxCount = 0 ;
1664
- for (unsigned s = 0 ; s < Size ; s ++) {
1665
- const PGOUseEdge *E = BBCountInfo.OutEdges [s ];
1670
+ for (unsigned It = 0 ; It < OutEdgesCount; It ++) {
1671
+ const PGOUseEdge *E = BBCountInfo.OutEdges [It ];
1666
1672
const BasicBlock *SrcBB = E->SrcBB ;
1667
1673
const BasicBlock *DestBB = E->DestBB ;
1668
1674
if (DestBB == nullptr )
Original file line number Diff line number Diff line change
1
+ ; RUN: rm -rf %t && split-file %s %t
2
+
3
+ ; RUN: llvm-profdata merge %t/a.proftext -o %t/a.profdata
4
+ ; RUN: opt < %t/a.ll --passes=pgo-instr-use -pgo-test-profile-file=%t/a.profdata
5
+
6
+ ;--- a.ll
7
+ target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
8
+ target triple = "x86_64-redhat-linux-gnu"
9
+
10
+ define void @_bar () presplitcoroutine personality ptr null {
11
+ %1 = call token @llvm.coro.save (ptr null )
12
+ %2 = call i8 @llvm.coro.suspend (token none, i1 false )
13
+ switch i8 %2 , label %5 [
14
+ i8 0 , label %3
15
+ i8 1 , label %4
16
+ ]
17
+
18
+ 3 : ; preds = %0
19
+ ret void
20
+
21
+ 4 : ; preds = %0
22
+ ret void
23
+
24
+ 5 : ; preds = %0
25
+ ret void
26
+ }
27
+
28
+ declare token @llvm.coro.save (ptr )
29
+
30
+ declare i8 @llvm.coro.suspend (token, i1 )
31
+
32
+ ;--- a.proftext
33
+ # IR level Instrumentation Flag
34
+ :ir
35
+
36
+ _bar
37
+ # Func Hash:
38
+ 1063705160175073211
39
+ # Num Counters:
40
+ 2
41
+ 1
42
+ 0
You can’t perform that action at this time.
0 commit comments