Skip to content

Commit e6e56f5

Browse files
[MemProf] Handle recursion during stack node update (#135837)
If we are replacing a sequence of stack nodes with a single node representing inlined IR, and the stack id sequence contains recursion, we may have already removed some edges. Handle this case correctly by skipping the now removed edge.
1 parent 4f64c80 commit e6e56f5

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

llvm/lib/Transforms/IPO/MemProfContextDisambiguation.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1711,7 +1711,12 @@ void CallsiteContextGraph<DerivedCCG, FuncTy, CallTy>::
17111711
// edge from the prior node.
17121712
if (PrevNode) {
17131713
auto *PrevEdge = CurNode->findEdgeFromCallee(PrevNode);
1714-
assert(PrevEdge);
1714+
// If the sequence contained recursion, we might have already removed
1715+
// some edges during the connectNewNode calls above.
1716+
if (!PrevEdge) {
1717+
PrevNode = CurNode;
1718+
continue;
1719+
}
17151720
set_subtract(PrevEdge->getContextIds(), SavedContextIds);
17161721
if (PrevEdge->getContextIds().empty())
17171722
removeEdgeFromGraph(PrevEdge);

llvm/test/Transforms/MemProfContextDisambiguation/inlined2.ll

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
;; in the input IR to ensure that the MIB call chain is matched to the longer
4141
;; inline sequences from main.
4242
;;
43+
;; Update: the inlined sequence of callsite ids was manually modified to
44+
;; include some recursion, which reproduced an error before it was fixed.
45+
;;
4346
;; The IR was then reduced using llvm-reduce with the expected FileCheck input.
4447

4548
; RUN: opt -passes=memprof-context-disambiguation -supports-hot-cold-new \
@@ -96,13 +99,13 @@ attributes #7 = { builtin }
9699
!6 = !{i32 7, !"frame-pointer", i32 2}
97100
!7 = !{!8, !10}
98101
!8 = !{!9, !"notcold"}
99-
!9 = !{i64 9086428284934609951, i64 -5964873800580613432, i64 2732490490862098848, i64 8632435727821051414}
102+
!9 = !{i64 9086428284934609951, i64 -5964873800580613432, i64 2732490490862098848, i64 -5964873800580613432, i64 8632435727821051414}
100103
!10 = !{!11, !"cold"}
101-
!11 = !{i64 9086428284934609951, i64 -5964873800580613432, i64 2732490490862098848, i64 -3421689549917153178}
104+
!11 = !{i64 9086428284934609951, i64 -5964873800580613432, i64 2732490490862098848, i64 -5964873800580613432, i64 -3421689549917153178}
102105
!12 = !{i64 9086428284934609951}
103106
!13 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
104-
!14 = !{i64 -5964873800580613432, i64 2732490490862098848, i64 8632435727821051414}
105-
!15 = !{i64 -5964873800580613432, i64 2732490490862098848, i64 -3421689549917153178}
107+
!14 = !{i64 -5964873800580613432, i64 2732490490862098848, i64 -5964873800580613432, i64 8632435727821051414}
108+
!15 = !{i64 -5964873800580613432, i64 2732490490862098848, i64 -5964873800580613432, i64 -3421689549917153178}
106109

107110

108111
; DUMP: CCG before cloning:

0 commit comments

Comments
 (0)