xref: /llvm-project/llvm/test/Transforms/MemProfContextDisambiguation/tailcall-nonunique.ll (revision b2f6d323fcd1833a7092e7d338578e0af0ac138d)
1;; Test to make sure that missing tail call frames in memprof profiles are
2;; identified but not cloned when there are multiple non-unique possible
3;; tail call chains between the profiled frames.
4
5;; -stats requires asserts
6; REQUIRES: asserts
7
8; RUN: opt -passes=memprof-context-disambiguation -supports-hot-cold-new \
9; RUN:  -stats -debug %s -S 2>&1 | FileCheck %s --check-prefix=STATS \
10; RUN:  --check-prefix=IR --check-prefix=DEBUG
11
12; DEBUG: Not found through unique tail call chain: _Z3barv from main that actually called xyz (found multiple possible chains)
13
14;; Check that all calls in the IR are to the original functions, leading to a
15;; non-cold operator new call.
16
17source_filename = "tailcall-nonunique.cc"
18target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
19target triple = "x86_64-unknown-linux-gnu"
20
21; Function Attrs: noinline
22; IR-LABEL: @_Z3barv()
23define dso_local ptr @_Z3barv() local_unnamed_addr #0 {
24entry:
25  ; IR: call ptr @_Znam(i64 10) #[[NOTCOLD:[0-9]+]]
26  %call = tail call ptr @_Znam(i64 10) #2, !memprof !0, !callsite !9
27  ret ptr %call
28}
29
30; Function Attrs: nobuiltin allocsize(0)
31declare ptr @_Znam(i64) #1
32
33; Function Attrs: noinline
34; IR-LABEL: @_Z5blah1v()
35define dso_local ptr @_Z5blah1v() local_unnamed_addr #0 {
36entry:
37  ; IR: call ptr @_Z3barv()
38  %call = tail call ptr @_Z3barv()
39  ret ptr %call
40}
41
42; Function Attrs: noinline
43; IR-LABEL: @_Z5blah2v()
44define dso_local ptr @_Z5blah2v() local_unnamed_addr #0 {
45entry:
46  ; IR: call ptr @_Z3barv()
47  %call = tail call ptr @_Z3barv()
48  ret ptr %call
49}
50
51; Function Attrs: noinline
52; IR-LABEL: @_Z4baz1v()
53define dso_local ptr @_Z4baz1v() local_unnamed_addr #0 {
54entry:
55  ; IR: call ptr @_Z5blah1v()
56  %call = tail call ptr @_Z5blah1v()
57  ret ptr %call
58}
59
60; Function Attrs: noinline
61; IR-LABEL: @_Z4baz2v()
62define dso_local ptr @_Z4baz2v() local_unnamed_addr #0 {
63entry:
64  ; IR: call ptr @_Z5blah2v()
65  %call = tail call ptr @_Z5blah2v()
66  ret ptr %call
67}
68
69; Function Attrs: noinline
70; IR-LABEL: @_Z3foob(i1 %b)
71define dso_local ptr @_Z3foob(i1 %b) local_unnamed_addr #0 {
72entry:
73  br i1 %b, label %if.then, label %if.else
74
75if.then:                                          ; preds = %entry
76  ; IR: call ptr @_Z4baz1v()
77  %call = tail call ptr @_Z4baz1v()
78  br label %return
79
80if.else:                                          ; preds = %entry
81  ; IR: call ptr @_Z4baz2v()
82  %call1 = tail call ptr @_Z4baz2v()
83  br label %return
84
85return:                                           ; preds = %if.else, %if.then
86  %retval.0 = phi ptr [ %call, %if.then ], [ %call1, %if.else ]
87  ret ptr %retval.0
88}
89
90; Function Attrs: noinline
91; IR-LABEL: @xyz()
92define dso_local i32 @xyz() local_unnamed_addr #0 {
93  ; IR: call ptr @_Z3foob(i1 true)
94  %call = tail call ptr @_Z3foob(i1 true)
95  ; IR: call ptr @_Z3foob(i1 true)
96  %call1 = tail call ptr @_Z3foob(i1 true)
97  ; IR: call ptr @_Z3foob(i1 false)
98  %call2 = tail call ptr @_Z3foob(i1 false)
99  ; IR: call ptr @_Z3foob(i1 false)
100  %call3 = tail call ptr @_Z3foob(i1 false)
101  ret i32 0
102}
103
104define dso_local i32 @main() local_unnamed_addr #0 {
105  ; IR: call i32 @xyz()
106  %call1 = tail call i32 @xyz(), !callsite !11
107  ret i32 0
108}
109
110; IR: attributes #[[NOTCOLD]] = { builtin allocsize(0) "memprof"="notcold" }
111
112; STATS: 1 memprof-context-disambiguation - Number of profiled callees found via multiple tail call chains
113
114attributes #0 = { noinline }
115attributes #1 = { nobuiltin allocsize(0) }
116attributes #2 = { builtin allocsize(0) }
117
118!0 = !{!5, !7}
119!5 = !{!6, !"notcold"}
120!6 = !{i64 3186456655321080972, i64 8632435727821051414}
121!7 = !{!8, !"cold"}
122!8 = !{i64 3186456655321080972, i64 -3421689549917153178}
123!9 = !{i64 3186456655321080972}
124!11 = !{i64 -3421689549917153178}
125