blob: 95d0c473ae7e3e47f63abd56e9bb7bab58ac22b4 [file] [log] [blame]
Dehao Chen77079002017-01-20 22:56:07 +00001; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/indirect-call.prof -S | FileCheck %s
Wei Mi94d44c92018-09-06 22:03:37 +00002; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/indirect-call.compact.afdo -S | FileCheck %s
Dehao Chen77079002017-01-20 22:56:07 +00003
Dehao Chen274df5e2017-01-31 17:49:37 +00004; CHECK-LABEL: @test
Dehao Chen77079002017-01-20 22:56:07 +00005define void @test(void ()*) !dbg !3 {
6 %2 = alloca void ()*
7 store void ()* %0, void ()** %2
8 %3 = load void ()*, void ()** %2
9 ; CHECK: call {{.*}}, !prof ![[PROF:[0-9]+]]
10 call void %3(), !dbg !4
11 ret void
12}
13
Dehao Chen274df5e2017-01-31 17:49:37 +000014; CHECK-LABEL: @test_inline
15; If the indirect call is promoted and inlined in profile, we should promote and inline it.
Adrian Prantldefc99a2017-05-04 16:24:31 +000016define void @test_inline(i64* (i32*)*, i32* %x) !dbg !6 {
Dehao Chenc81483d2017-02-06 18:10:36 +000017 %2 = alloca i64* (i32*)*
18 store i64* (i32*)* %0, i64* (i32*)** %2
19 %3 = load i64* (i32*)*, i64* (i32*)** %2
Dehao Chen2c7ca9b2017-04-13 19:52:10 +000020; CHECK: icmp {{.*}} @foo_inline2
Dehao Chen3f56a052017-10-10 21:13:50 +000021; CHECK: br {{.*}} !prof ![[BR1:[0-9]+]]
Dehao Chen274df5e2017-01-31 17:49:37 +000022; CHECK: if.true.direct_targ:
23; CHECK-NOT: call
24; CHECK: if.false.orig_indirect:
Dehao Chen2c7ca9b2017-04-13 19:52:10 +000025; CHECK: icmp {{.*}} @foo_inline1
Dehao Chen3f56a052017-10-10 21:13:50 +000026; CHECK: br {{.*}} !prof ![[BR2:[0-9]+]]
Dehao Chen2c7ca9b2017-04-13 19:52:10 +000027; CHECK: if.true.direct_targ1:
28; CHECK-NOT: call
29; CHECK: if.false.orig_indirect2:
Dehao Chen16f01fb2017-10-05 20:15:29 +000030; CHECK: call {{.*}} !prof ![[VP:[0-9]+]]
Adrian Prantldefc99a2017-05-04 16:24:31 +000031 call i64* %3(i32* %x), !dbg !7
Dehao Chen274df5e2017-01-31 17:49:37 +000032 ret void
33}
34
Dehao Chen1ea8bd82017-04-17 22:23:05 +000035; CHECK-LABEL: @test_inline_strip
36; If the indirect call is promoted and inlined in profile, and the callee name
37; is stripped we should promote and inline it.
Adrian Prantldefc99a2017-05-04 16:24:31 +000038define void @test_inline_strip(i64* (i32*)*, i32* %x) !dbg !8 {
Dehao Chen1ea8bd82017-04-17 22:23:05 +000039 %2 = alloca i64* (i32*)*
40 store i64* (i32*)* %0, i64* (i32*)** %2
41 %3 = load i64* (i32*)*, i64* (i32*)** %2
42; CHECK: icmp {{.*}} @foo_inline_strip.suffix
43; CHECK: if.true.direct_targ:
44; CHECK-NOT: call
45; CHECK: if.false.orig_indirect:
46; CHECK: call
Adrian Prantldefc99a2017-05-04 16:24:31 +000047 call i64* %3(i32* %x), !dbg !9
Dehao Chen1ea8bd82017-04-17 22:23:05 +000048 ret void
49}
50
51; CHECK-LABEL: @test_inline_strip_conflict
52; If the indirect call is promoted and inlined in profile, and the callee name
53; is stripped, but have more than 1 potential match, we should not promote.
Adrian Prantldefc99a2017-05-04 16:24:31 +000054define void @test_inline_strip_conflict(i64* (i32*)*, i32* %x) !dbg !10 {
Dehao Chen1ea8bd82017-04-17 22:23:05 +000055 %2 = alloca i64* (i32*)*
56 store i64* (i32*)* %0, i64* (i32*)** %2
57 %3 = load i64* (i32*)*, i64* (i32*)** %2
58; CHECK-NOT: if.true.direct_targ:
Adrian Prantldefc99a2017-05-04 16:24:31 +000059 call i64* %3(i32* %x), !dbg !11
Dehao Chen1ea8bd82017-04-17 22:23:05 +000060 ret void
61}
62
Dehao Chen274df5e2017-01-31 17:49:37 +000063; CHECK-LABEL: @test_noinline
64; If the indirect call target is not available, we should not promote it.
Adrian Prantldefc99a2017-05-04 16:24:31 +000065define void @test_noinline(void ()*) !dbg !12 {
Dehao Chen274df5e2017-01-31 17:49:37 +000066 %2 = alloca void ()*
67 store void ()* %0, void ()** %2
68 %3 = load void ()*, void ()** %2
69; CHECK-NOT: icmp
70; CHECK: call
Adrian Prantldefc99a2017-05-04 16:24:31 +000071 call void %3(), !dbg !13
Dehao Chen274df5e2017-01-31 17:49:37 +000072 ret void
73}
74
Dehao Chenb6e60c82017-09-19 18:26:54 +000075; CHECK-LABEL: @test_noinline_bitcast
76; If the indirect call has been promoted to a direct call with bitcast,
77; do not inline it.
78define float @test_noinline_bitcast(float ()*) !dbg !26 {
79 %2 = alloca float ()*
80 store float ()* %0, float ()** %2
81; CHECK: icmp
82; CHECK: call
83 %3 = load float ()*, float ()** %2
84 %4 = call float %3(), !dbg !27
85 ret float %4
86}
87
Dehao Chene2a428b2017-06-08 20:11:57 +000088; CHECK-LABEL: @test_norecursive_inline
89; If the indirect call target is the caller, we should not promote it.
90define void @test_norecursive_inline() !dbg !24 {
91; CHECK-NOT: icmp
92; CHECK: call
93 %1 = load void ()*, void ()** @y, align 8
94 call void %1(), !dbg !25
95 ret void
96}
97
Dehao Chen9bd60422017-10-06 17:04:55 +000098define i32* @return_arg(i32* readnone returned) !dbg !29{
99 ret i32* %0
100}
101
102; CHECK-LABEL: @return_arg_caller
103; When the promoted indirect call returns a parameter that was defined by the
104; return value of a previous direct call. Checks both direct call and promoted
105; indirect call are inlined.
106define i32* @return_arg_caller(i32* (i32*)* nocapture) !dbg !30{
107; CHECK-NOT: call i32* @foo_inline1
108; CHECK: if.true.direct_targ:
109; CHECK-NOT: call
110; CHECK: if.false.orig_indirect:
111; CHECK: call
112 %2 = call i32* @foo_inline1(i32* null), !dbg !31
113 %cmp = icmp ne i32* %2, null
114 br i1 %cmp, label %then, label %else
115
116then:
117 %3 = tail call i32* %0(i32* %2), !dbg !32
118 ret i32* %3
119
120else:
121 ret i32* null
122}
123
Dehao Chenc81483d2017-02-06 18:10:36 +0000124@x = global i32 0, align 4
Dehao Chene2a428b2017-06-08 20:11:57 +0000125@y = global void ()* null, align 8
Dehao Chenc81483d2017-02-06 18:10:36 +0000126
Adrian Prantldefc99a2017-05-04 16:24:31 +0000127define i32* @foo_inline1(i32* %x) !dbg !14 {
Dehao Chen2c7ca9b2017-04-13 19:52:10 +0000128 ret i32* %x
129}
130
Adrian Prantldefc99a2017-05-04 16:24:31 +0000131define i32* @foo_inline_strip.suffix(i32* %x) !dbg !15 {
Dehao Chen1ea8bd82017-04-17 22:23:05 +0000132 ret i32* %x
133}
134
Adrian Prantldefc99a2017-05-04 16:24:31 +0000135define i32* @foo_inline_strip_conflict.suffix1(i32* %x) !dbg !16 {
Dehao Chen1ea8bd82017-04-17 22:23:05 +0000136 ret i32* %x
137}
138
Adrian Prantldefc99a2017-05-04 16:24:31 +0000139define i32* @foo_inline_strip_conflict.suffix2(i32* %x) !dbg !17 {
Dehao Chen1ea8bd82017-04-17 22:23:05 +0000140 ret i32* %x
141}
142
Adrian Prantldefc99a2017-05-04 16:24:31 +0000143define i32* @foo_inline_strip_conflict.suffix3(i32* %x) !dbg !18 {
Dehao Chen1ea8bd82017-04-17 22:23:05 +0000144 ret i32* %x
145}
146
Adrian Prantldefc99a2017-05-04 16:24:31 +0000147define i32* @foo_inline2(i32* %x) !dbg !19 {
Dehao Chenc81483d2017-02-06 18:10:36 +0000148 ret i32* %x
Dehao Chen274df5e2017-01-31 17:49:37 +0000149}
150
Adrian Prantldefc99a2017-05-04 16:24:31 +0000151define i32 @foo_noinline(i32 %x) !dbg !20 {
Dehao Chen274df5e2017-01-31 17:49:37 +0000152 ret i32 %x
153}
154
Adrian Prantldefc99a2017-05-04 16:24:31 +0000155define void @foo_direct() !dbg !21 {
Dehao Chen4a9dd702017-02-06 23:33:15 +0000156 ret void
157}
158
Dehao Chenb6e60c82017-09-19 18:26:54 +0000159define i32 @foo_direct_i32() !dbg !28 {
160 ret i32 0;
161}
162
Dehao Chen4a9dd702017-02-06 23:33:15 +0000163; CHECK-LABEL: @test_direct
164; We should not promote a direct call.
Adrian Prantldefc99a2017-05-04 16:24:31 +0000165define void @test_direct() !dbg !22 {
Dehao Chen4a9dd702017-02-06 23:33:15 +0000166; CHECK-NOT: icmp
167; CHECK: call
Adrian Prantldefc99a2017-05-04 16:24:31 +0000168 call void @foo_alias(), !dbg !23
Dehao Chen4a9dd702017-02-06 23:33:15 +0000169 ret void
170}
171
172@foo_alias = alias void (), void ()* @foo_direct
173
Dehao Chen77079002017-01-20 22:56:07 +0000174!llvm.dbg.cu = !{!0}
175!llvm.module.flags = !{!2}
176
177!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1)
178!1 = !DIFile(filename: "test.cc", directory: "/")
179!2 = !{i32 2, !"Debug Info Version", i32 3}
Adrian Prantldefc99a2017-05-04 16:24:31 +0000180!3 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 3, unit: !0)
181!4 = !DILocation(line: 4, scope: !3)
Dehao Chen274df5e2017-01-31 17:49:37 +0000182!5 = !DILocation(line: 6, scope: !3)
Dehao Chen77079002017-01-20 22:56:07 +0000183; CHECK: ![[PROF]] = !{!"VP", i32 0, i64 3457, i64 9191153033785521275, i64 2059, i64 -1069303473483922844, i64 1398}
Dehao Chen3f56a052017-10-10 21:13:50 +0000184; CHECK: ![[BR1]] = !{!"branch_weights", i32 4000, i32 4000}
185; CHECK: ![[BR2]] = !{!"branch_weights", i32 3000, i32 1000}
Dehao Chen5d2a1a52017-11-06 19:52:49 +0000186; CHECK: ![[VP]] = !{!"VP", i32 0, i64 8000, i64 -6391416044382067764, i64 1000}
Adrian Prantldefc99a2017-05-04 16:24:31 +0000187!6 = distinct !DISubprogram(name: "test_inline", scope: !1, file: !1, line: 6, unit: !0)
188!7 = !DILocation(line: 7, scope: !6)
189!8 = distinct !DISubprogram(name: "test_inline_strip", scope: !1, file: !1, line: 8, unit: !0)
190!9 = !DILocation(line: 9, scope: !8)
191!10 = distinct !DISubprogram(name: "test_inline_strip_conflict", scope: !1, file: !1, line: 10, unit: !0)
192!11 = !DILocation(line: 11, scope: !10)
193!12 = distinct !DISubprogram(name: "test_noinline", scope: !1, file: !1, line: 12, unit: !0)
194!13 = !DILocation(line: 13, scope: !12)
195!14 = distinct !DISubprogram(name: "foo_inline1", scope: !1, file: !1, line: 11, unit: !0)
196!15 = distinct !DISubprogram(name: "foo_inline_strip.suffix", scope: !1, file: !1, line: 1, unit: !0)
197!16 = distinct !DISubprogram(name: "foo_inline_strip_conflict.suffix1", scope: !1, file: !1, line: 1, unit: !0)
198!17 = distinct !DISubprogram(name: "foo_inline_strip_conflict.suffix2", scope: !1, file: !1, line: 1, unit: !0)
199!18 = distinct !DISubprogram(name: "foo_inline_strip_conflict.suffix3", scope: !1, file: !1, line: 1, unit: !0)
200!19 = distinct !DISubprogram(name: "foo_inline2", scope: !1, file: !1, line: 19, unit: !0)
201!20 = distinct !DISubprogram(name: "foo_noinline", scope: !1, file: !1, line: 20, unit: !0)
202!21 = distinct !DISubprogram(name: "foo_direct", scope: !1, file: !1, line: 21, unit: !0)
203!22 = distinct !DISubprogram(name: "test_direct", scope: !1, file: !1, line: 22, unit: !0)
204!23 = !DILocation(line: 23, scope: !22)
Dehao Chene2a428b2017-06-08 20:11:57 +0000205!24 = distinct !DISubprogram(name: "test_norecursive_inline", scope: !1, file: !1, line: 12, unit: !0)
206!25 = !DILocation(line: 13, scope: !24)
Dehao Chenb6e60c82017-09-19 18:26:54 +0000207!26 = distinct !DISubprogram(name: "test_noinline_bitcast", scope: !1, file: !1, line: 12, unit: !0)
208!27 = !DILocation(line: 13, scope: !26)
209!28 = distinct !DISubprogram(name: "foo_direct_i32", scope: !1, file: !1, line: 11, unit: !0)
Dehao Chen9bd60422017-10-06 17:04:55 +0000210!29 = distinct !DISubprogram(name: "return_arg", scope: !1, file: !1, line: 11, unit: !0)
211!30 = distinct !DISubprogram(name: "return_arg_caller", scope: !1, file: !1, line: 11, unit: !0)
212!31 = !DILocation(line: 12, scope: !30)
213!32 = !DILocation(line: 13, scope: !30)