blob: 61a1bc51996610adfd62450def3065fbadceffc3 [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
2
Dehao Chen274df5e2017-01-31 17:49:37 +00003; CHECK-LABEL: @test
Dehao Chen77079002017-01-20 22:56:07 +00004define void @test(void ()*) !dbg !3 {
5 %2 = alloca void ()*
6 store void ()* %0, void ()** %2
7 %3 = load void ()*, void ()** %2
8 ; CHECK: call {{.*}}, !prof ![[PROF:[0-9]+]]
9 call void %3(), !dbg !4
10 ret void
11}
12
Dehao Chen274df5e2017-01-31 17:49:37 +000013; CHECK-LABEL: @test_inline
14; If the indirect call is promoted and inlined in profile, we should promote and inline it.
Adrian Prantldefc99a2017-05-04 16:24:31 +000015define void @test_inline(i64* (i32*)*, i32* %x) !dbg !6 {
Dehao Chenc81483d2017-02-06 18:10:36 +000016 %2 = alloca i64* (i32*)*
17 store i64* (i32*)* %0, i64* (i32*)** %2
18 %3 = load i64* (i32*)*, i64* (i32*)** %2
Dehao Chen2c7ca9b2017-04-13 19:52:10 +000019; CHECK: icmp {{.*}} @foo_inline2
Dehao Chen3f56a052017-10-10 21:13:50 +000020; CHECK: br {{.*}} !prof ![[BR1:[0-9]+]]
Dehao Chen274df5e2017-01-31 17:49:37 +000021; CHECK: if.true.direct_targ:
22; CHECK-NOT: call
23; CHECK: if.false.orig_indirect:
Dehao Chen2c7ca9b2017-04-13 19:52:10 +000024; CHECK: icmp {{.*}} @foo_inline1
Dehao Chen3f56a052017-10-10 21:13:50 +000025; CHECK: br {{.*}} !prof ![[BR2:[0-9]+]]
Dehao Chen2c7ca9b2017-04-13 19:52:10 +000026; CHECK: if.true.direct_targ1:
27; CHECK-NOT: call
28; CHECK: if.false.orig_indirect2:
Dehao Chen16f01fb2017-10-05 20:15:29 +000029; CHECK: call {{.*}} !prof ![[VP:[0-9]+]]
Adrian Prantldefc99a2017-05-04 16:24:31 +000030 call i64* %3(i32* %x), !dbg !7
Dehao Chen274df5e2017-01-31 17:49:37 +000031 ret void
32}
33
Dehao Chen1ea8bd82017-04-17 22:23:05 +000034; CHECK-LABEL: @test_inline_strip
35; If the indirect call is promoted and inlined in profile, and the callee name
36; is stripped we should promote and inline it.
Adrian Prantldefc99a2017-05-04 16:24:31 +000037define void @test_inline_strip(i64* (i32*)*, i32* %x) !dbg !8 {
Dehao Chen1ea8bd82017-04-17 22:23:05 +000038 %2 = alloca i64* (i32*)*
39 store i64* (i32*)* %0, i64* (i32*)** %2
40 %3 = load i64* (i32*)*, i64* (i32*)** %2
41; CHECK: icmp {{.*}} @foo_inline_strip.suffix
42; CHECK: if.true.direct_targ:
43; CHECK-NOT: call
44; CHECK: if.false.orig_indirect:
45; CHECK: call
Adrian Prantldefc99a2017-05-04 16:24:31 +000046 call i64* %3(i32* %x), !dbg !9
Dehao Chen1ea8bd82017-04-17 22:23:05 +000047 ret void
48}
49
50; CHECK-LABEL: @test_inline_strip_conflict
51; If the indirect call is promoted and inlined in profile, and the callee name
52; is stripped, but have more than 1 potential match, we should not promote.
Adrian Prantldefc99a2017-05-04 16:24:31 +000053define void @test_inline_strip_conflict(i64* (i32*)*, i32* %x) !dbg !10 {
Dehao Chen1ea8bd82017-04-17 22:23:05 +000054 %2 = alloca i64* (i32*)*
55 store i64* (i32*)* %0, i64* (i32*)** %2
56 %3 = load i64* (i32*)*, i64* (i32*)** %2
57; CHECK-NOT: if.true.direct_targ:
Adrian Prantldefc99a2017-05-04 16:24:31 +000058 call i64* %3(i32* %x), !dbg !11
Dehao Chen1ea8bd82017-04-17 22:23:05 +000059 ret void
60}
61
Dehao Chen274df5e2017-01-31 17:49:37 +000062; CHECK-LABEL: @test_noinline
63; If the indirect call target is not available, we should not promote it.
Adrian Prantldefc99a2017-05-04 16:24:31 +000064define void @test_noinline(void ()*) !dbg !12 {
Dehao Chen274df5e2017-01-31 17:49:37 +000065 %2 = alloca void ()*
66 store void ()* %0, void ()** %2
67 %3 = load void ()*, void ()** %2
68; CHECK-NOT: icmp
69; CHECK: call
Adrian Prantldefc99a2017-05-04 16:24:31 +000070 call void %3(), !dbg !13
Dehao Chen274df5e2017-01-31 17:49:37 +000071 ret void
72}
73
Dehao Chenb6e60c82017-09-19 18:26:54 +000074; CHECK-LABEL: @test_noinline_bitcast
75; If the indirect call has been promoted to a direct call with bitcast,
76; do not inline it.
77define float @test_noinline_bitcast(float ()*) !dbg !26 {
78 %2 = alloca float ()*
79 store float ()* %0, float ()** %2
80; CHECK: icmp
81; CHECK: call
82 %3 = load float ()*, float ()** %2
83 %4 = call float %3(), !dbg !27
84 ret float %4
85}
86
Dehao Chene2a428b2017-06-08 20:11:57 +000087; CHECK-LABEL: @test_norecursive_inline
88; If the indirect call target is the caller, we should not promote it.
89define void @test_norecursive_inline() !dbg !24 {
90; CHECK-NOT: icmp
91; CHECK: call
92 %1 = load void ()*, void ()** @y, align 8
93 call void %1(), !dbg !25
94 ret void
95}
96
Dehao Chen9bd60422017-10-06 17:04:55 +000097define i32* @return_arg(i32* readnone returned) !dbg !29{
98 ret i32* %0
99}
100
101; CHECK-LABEL: @return_arg_caller
102; When the promoted indirect call returns a parameter that was defined by the
103; return value of a previous direct call. Checks both direct call and promoted
104; indirect call are inlined.
105define i32* @return_arg_caller(i32* (i32*)* nocapture) !dbg !30{
106; CHECK-NOT: call i32* @foo_inline1
107; CHECK: if.true.direct_targ:
108; CHECK-NOT: call
109; CHECK: if.false.orig_indirect:
110; CHECK: call
111 %2 = call i32* @foo_inline1(i32* null), !dbg !31
112 %cmp = icmp ne i32* %2, null
113 br i1 %cmp, label %then, label %else
114
115then:
116 %3 = tail call i32* %0(i32* %2), !dbg !32
117 ret i32* %3
118
119else:
120 ret i32* null
121}
122
Dehao Chenc81483d2017-02-06 18:10:36 +0000123@x = global i32 0, align 4
Dehao Chene2a428b2017-06-08 20:11:57 +0000124@y = global void ()* null, align 8
Dehao Chenc81483d2017-02-06 18:10:36 +0000125
Adrian Prantldefc99a2017-05-04 16:24:31 +0000126define i32* @foo_inline1(i32* %x) !dbg !14 {
Dehao Chen2c7ca9b2017-04-13 19:52:10 +0000127 ret i32* %x
128}
129
Adrian Prantldefc99a2017-05-04 16:24:31 +0000130define i32* @foo_inline_strip.suffix(i32* %x) !dbg !15 {
Dehao Chen1ea8bd82017-04-17 22:23:05 +0000131 ret i32* %x
132}
133
Adrian Prantldefc99a2017-05-04 16:24:31 +0000134define i32* @foo_inline_strip_conflict.suffix1(i32* %x) !dbg !16 {
Dehao Chen1ea8bd82017-04-17 22:23:05 +0000135 ret i32* %x
136}
137
Adrian Prantldefc99a2017-05-04 16:24:31 +0000138define i32* @foo_inline_strip_conflict.suffix2(i32* %x) !dbg !17 {
Dehao Chen1ea8bd82017-04-17 22:23:05 +0000139 ret i32* %x
140}
141
Adrian Prantldefc99a2017-05-04 16:24:31 +0000142define i32* @foo_inline_strip_conflict.suffix3(i32* %x) !dbg !18 {
Dehao Chen1ea8bd82017-04-17 22:23:05 +0000143 ret i32* %x
144}
145
Adrian Prantldefc99a2017-05-04 16:24:31 +0000146define i32* @foo_inline2(i32* %x) !dbg !19 {
Dehao Chenc81483d2017-02-06 18:10:36 +0000147 ret i32* %x
Dehao Chen274df5e2017-01-31 17:49:37 +0000148}
149
Adrian Prantldefc99a2017-05-04 16:24:31 +0000150define i32 @foo_noinline(i32 %x) !dbg !20 {
Dehao Chen274df5e2017-01-31 17:49:37 +0000151 ret i32 %x
152}
153
Adrian Prantldefc99a2017-05-04 16:24:31 +0000154define void @foo_direct() !dbg !21 {
Dehao Chen4a9dd702017-02-06 23:33:15 +0000155 ret void
156}
157
Dehao Chenb6e60c82017-09-19 18:26:54 +0000158define i32 @foo_direct_i32() !dbg !28 {
159 ret i32 0;
160}
161
Dehao Chen4a9dd702017-02-06 23:33:15 +0000162; CHECK-LABEL: @test_direct
163; We should not promote a direct call.
Adrian Prantldefc99a2017-05-04 16:24:31 +0000164define void @test_direct() !dbg !22 {
Dehao Chen4a9dd702017-02-06 23:33:15 +0000165; CHECK-NOT: icmp
166; CHECK: call
Adrian Prantldefc99a2017-05-04 16:24:31 +0000167 call void @foo_alias(), !dbg !23
Dehao Chen4a9dd702017-02-06 23:33:15 +0000168 ret void
169}
170
171@foo_alias = alias void (), void ()* @foo_direct
172
Dehao Chen77079002017-01-20 22:56:07 +0000173!llvm.dbg.cu = !{!0}
174!llvm.module.flags = !{!2}
175
176!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1)
177!1 = !DIFile(filename: "test.cc", directory: "/")
178!2 = !{i32 2, !"Debug Info Version", i32 3}
Adrian Prantldefc99a2017-05-04 16:24:31 +0000179!3 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 3, unit: !0)
180!4 = !DILocation(line: 4, scope: !3)
Dehao Chen274df5e2017-01-31 17:49:37 +0000181!5 = !DILocation(line: 6, scope: !3)
Dehao Chen77079002017-01-20 22:56:07 +0000182; CHECK: ![[PROF]] = !{!"VP", i32 0, i64 3457, i64 9191153033785521275, i64 2059, i64 -1069303473483922844, i64 1398}
Dehao Chen3f56a052017-10-10 21:13:50 +0000183; CHECK: ![[BR1]] = !{!"branch_weights", i32 4000, i32 4000}
184; CHECK: ![[BR2]] = !{!"branch_weights", i32 3000, i32 1000}
Dehao Chen16f01fb2017-10-05 20:15:29 +0000185; CHECK: ![[VP]] = !{!"VP", i32 0, i64 1000, i64 -6391416044382067764, i64 1000}
Adrian Prantldefc99a2017-05-04 16:24:31 +0000186!6 = distinct !DISubprogram(name: "test_inline", scope: !1, file: !1, line: 6, unit: !0)
187!7 = !DILocation(line: 7, scope: !6)
188!8 = distinct !DISubprogram(name: "test_inline_strip", scope: !1, file: !1, line: 8, unit: !0)
189!9 = !DILocation(line: 9, scope: !8)
190!10 = distinct !DISubprogram(name: "test_inline_strip_conflict", scope: !1, file: !1, line: 10, unit: !0)
191!11 = !DILocation(line: 11, scope: !10)
192!12 = distinct !DISubprogram(name: "test_noinline", scope: !1, file: !1, line: 12, unit: !0)
193!13 = !DILocation(line: 13, scope: !12)
194!14 = distinct !DISubprogram(name: "foo_inline1", scope: !1, file: !1, line: 11, unit: !0)
195!15 = distinct !DISubprogram(name: "foo_inline_strip.suffix", scope: !1, file: !1, line: 1, unit: !0)
196!16 = distinct !DISubprogram(name: "foo_inline_strip_conflict.suffix1", scope: !1, file: !1, line: 1, unit: !0)
197!17 = distinct !DISubprogram(name: "foo_inline_strip_conflict.suffix2", scope: !1, file: !1, line: 1, unit: !0)
198!18 = distinct !DISubprogram(name: "foo_inline_strip_conflict.suffix3", scope: !1, file: !1, line: 1, unit: !0)
199!19 = distinct !DISubprogram(name: "foo_inline2", scope: !1, file: !1, line: 19, unit: !0)
200!20 = distinct !DISubprogram(name: "foo_noinline", scope: !1, file: !1, line: 20, unit: !0)
201!21 = distinct !DISubprogram(name: "foo_direct", scope: !1, file: !1, line: 21, unit: !0)
202!22 = distinct !DISubprogram(name: "test_direct", scope: !1, file: !1, line: 22, unit: !0)
203!23 = !DILocation(line: 23, scope: !22)
Dehao Chene2a428b2017-06-08 20:11:57 +0000204!24 = distinct !DISubprogram(name: "test_norecursive_inline", scope: !1, file: !1, line: 12, unit: !0)
205!25 = !DILocation(line: 13, scope: !24)
Dehao Chenb6e60c82017-09-19 18:26:54 +0000206!26 = distinct !DISubprogram(name: "test_noinline_bitcast", scope: !1, file: !1, line: 12, unit: !0)
207!27 = !DILocation(line: 13, scope: !26)
208!28 = distinct !DISubprogram(name: "foo_direct_i32", scope: !1, file: !1, line: 11, unit: !0)
Dehao Chen9bd60422017-10-06 17:04:55 +0000209!29 = distinct !DISubprogram(name: "return_arg", scope: !1, file: !1, line: 11, unit: !0)
210!30 = distinct !DISubprogram(name: "return_arg_caller", scope: !1, file: !1, line: 11, unit: !0)
211!31 = !DILocation(line: 12, scope: !30)
212!32 = !DILocation(line: 13, scope: !30)