blob: 02fcb11060a4a4607cf64ef883eb18a36a18f638 [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 Chen274df5e2017-01-31 17:49:37 +000020; CHECK: if.true.direct_targ:
21; CHECK-NOT: call
22; CHECK: if.false.orig_indirect:
Dehao Chen2c7ca9b2017-04-13 19:52:10 +000023; CHECK: icmp {{.*}} @foo_inline1
24; CHECK: if.true.direct_targ1:
25; CHECK-NOT: call
26; CHECK: if.false.orig_indirect2:
Dehao Chen16f01fb2017-10-05 20:15:29 +000027; CHECK: call {{.*}} !prof ![[VP:[0-9]+]]
Adrian Prantldefc99a2017-05-04 16:24:31 +000028 call i64* %3(i32* %x), !dbg !7
Dehao Chen274df5e2017-01-31 17:49:37 +000029 ret void
30}
31
Dehao Chen1ea8bd82017-04-17 22:23:05 +000032; CHECK-LABEL: @test_inline_strip
33; If the indirect call is promoted and inlined in profile, and the callee name
34; is stripped we should promote and inline it.
Adrian Prantldefc99a2017-05-04 16:24:31 +000035define void @test_inline_strip(i64* (i32*)*, i32* %x) !dbg !8 {
Dehao Chen1ea8bd82017-04-17 22:23:05 +000036 %2 = alloca i64* (i32*)*
37 store i64* (i32*)* %0, i64* (i32*)** %2
38 %3 = load i64* (i32*)*, i64* (i32*)** %2
39; CHECK: icmp {{.*}} @foo_inline_strip.suffix
40; CHECK: if.true.direct_targ:
41; CHECK-NOT: call
42; CHECK: if.false.orig_indirect:
43; CHECK: call
Adrian Prantldefc99a2017-05-04 16:24:31 +000044 call i64* %3(i32* %x), !dbg !9
Dehao Chen1ea8bd82017-04-17 22:23:05 +000045 ret void
46}
47
48; CHECK-LABEL: @test_inline_strip_conflict
49; If the indirect call is promoted and inlined in profile, and the callee name
50; is stripped, but have more than 1 potential match, we should not promote.
Adrian Prantldefc99a2017-05-04 16:24:31 +000051define void @test_inline_strip_conflict(i64* (i32*)*, i32* %x) !dbg !10 {
Dehao Chen1ea8bd82017-04-17 22:23:05 +000052 %2 = alloca i64* (i32*)*
53 store i64* (i32*)* %0, i64* (i32*)** %2
54 %3 = load i64* (i32*)*, i64* (i32*)** %2
55; CHECK-NOT: if.true.direct_targ:
Adrian Prantldefc99a2017-05-04 16:24:31 +000056 call i64* %3(i32* %x), !dbg !11
Dehao Chen1ea8bd82017-04-17 22:23:05 +000057 ret void
58}
59
Dehao Chen274df5e2017-01-31 17:49:37 +000060; CHECK-LABEL: @test_noinline
61; If the indirect call target is not available, we should not promote it.
Adrian Prantldefc99a2017-05-04 16:24:31 +000062define void @test_noinline(void ()*) !dbg !12 {
Dehao Chen274df5e2017-01-31 17:49:37 +000063 %2 = alloca void ()*
64 store void ()* %0, void ()** %2
65 %3 = load void ()*, void ()** %2
66; CHECK-NOT: icmp
67; CHECK: call
Adrian Prantldefc99a2017-05-04 16:24:31 +000068 call void %3(), !dbg !13
Dehao Chen274df5e2017-01-31 17:49:37 +000069 ret void
70}
71
Dehao Chenb6e60c82017-09-19 18:26:54 +000072; CHECK-LABEL: @test_noinline_bitcast
73; If the indirect call has been promoted to a direct call with bitcast,
74; do not inline it.
75define float @test_noinline_bitcast(float ()*) !dbg !26 {
76 %2 = alloca float ()*
77 store float ()* %0, float ()** %2
78; CHECK: icmp
79; CHECK: call
80 %3 = load float ()*, float ()** %2
81 %4 = call float %3(), !dbg !27
82 ret float %4
83}
84
Dehao Chene2a428b2017-06-08 20:11:57 +000085; CHECK-LABEL: @test_norecursive_inline
86; If the indirect call target is the caller, we should not promote it.
87define void @test_norecursive_inline() !dbg !24 {
88; CHECK-NOT: icmp
89; CHECK: call
90 %1 = load void ()*, void ()** @y, align 8
91 call void %1(), !dbg !25
92 ret void
93}
94
Dehao Chenc81483d2017-02-06 18:10:36 +000095@x = global i32 0, align 4
Dehao Chene2a428b2017-06-08 20:11:57 +000096@y = global void ()* null, align 8
Dehao Chenc81483d2017-02-06 18:10:36 +000097
Adrian Prantldefc99a2017-05-04 16:24:31 +000098define i32* @foo_inline1(i32* %x) !dbg !14 {
Dehao Chen2c7ca9b2017-04-13 19:52:10 +000099 ret i32* %x
100}
101
Adrian Prantldefc99a2017-05-04 16:24:31 +0000102define i32* @foo_inline_strip.suffix(i32* %x) !dbg !15 {
Dehao Chen1ea8bd82017-04-17 22:23:05 +0000103 ret i32* %x
104}
105
Adrian Prantldefc99a2017-05-04 16:24:31 +0000106define i32* @foo_inline_strip_conflict.suffix1(i32* %x) !dbg !16 {
Dehao Chen1ea8bd82017-04-17 22:23:05 +0000107 ret i32* %x
108}
109
Adrian Prantldefc99a2017-05-04 16:24:31 +0000110define i32* @foo_inline_strip_conflict.suffix2(i32* %x) !dbg !17 {
Dehao Chen1ea8bd82017-04-17 22:23:05 +0000111 ret i32* %x
112}
113
Adrian Prantldefc99a2017-05-04 16:24:31 +0000114define i32* @foo_inline_strip_conflict.suffix3(i32* %x) !dbg !18 {
Dehao Chen1ea8bd82017-04-17 22:23:05 +0000115 ret i32* %x
116}
117
Adrian Prantldefc99a2017-05-04 16:24:31 +0000118define i32* @foo_inline2(i32* %x) !dbg !19 {
Dehao Chenc81483d2017-02-06 18:10:36 +0000119 ret i32* %x
Dehao Chen274df5e2017-01-31 17:49:37 +0000120}
121
Adrian Prantldefc99a2017-05-04 16:24:31 +0000122define i32 @foo_noinline(i32 %x) !dbg !20 {
Dehao Chen274df5e2017-01-31 17:49:37 +0000123 ret i32 %x
124}
125
Adrian Prantldefc99a2017-05-04 16:24:31 +0000126define void @foo_direct() !dbg !21 {
Dehao Chen4a9dd702017-02-06 23:33:15 +0000127 ret void
128}
129
Dehao Chenb6e60c82017-09-19 18:26:54 +0000130define i32 @foo_direct_i32() !dbg !28 {
131 ret i32 0;
132}
133
Dehao Chen4a9dd702017-02-06 23:33:15 +0000134; CHECK-LABEL: @test_direct
135; We should not promote a direct call.
Adrian Prantldefc99a2017-05-04 16:24:31 +0000136define void @test_direct() !dbg !22 {
Dehao Chen4a9dd702017-02-06 23:33:15 +0000137; CHECK-NOT: icmp
138; CHECK: call
Adrian Prantldefc99a2017-05-04 16:24:31 +0000139 call void @foo_alias(), !dbg !23
Dehao Chen4a9dd702017-02-06 23:33:15 +0000140 ret void
141}
142
143@foo_alias = alias void (), void ()* @foo_direct
144
Dehao Chen77079002017-01-20 22:56:07 +0000145!llvm.dbg.cu = !{!0}
146!llvm.module.flags = !{!2}
147
148!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1)
149!1 = !DIFile(filename: "test.cc", directory: "/")
150!2 = !{i32 2, !"Debug Info Version", i32 3}
Adrian Prantldefc99a2017-05-04 16:24:31 +0000151!3 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 3, unit: !0)
152!4 = !DILocation(line: 4, scope: !3)
Dehao Chen274df5e2017-01-31 17:49:37 +0000153!5 = !DILocation(line: 6, scope: !3)
Dehao Chen77079002017-01-20 22:56:07 +0000154; CHECK: ![[PROF]] = !{!"VP", i32 0, i64 3457, i64 9191153033785521275, i64 2059, i64 -1069303473483922844, i64 1398}
Dehao Chen16f01fb2017-10-05 20:15:29 +0000155; CHECK: ![[VP]] = !{!"VP", i32 0, i64 1000, i64 -6391416044382067764, i64 1000}
Adrian Prantldefc99a2017-05-04 16:24:31 +0000156!6 = distinct !DISubprogram(name: "test_inline", scope: !1, file: !1, line: 6, unit: !0)
157!7 = !DILocation(line: 7, scope: !6)
158!8 = distinct !DISubprogram(name: "test_inline_strip", scope: !1, file: !1, line: 8, unit: !0)
159!9 = !DILocation(line: 9, scope: !8)
160!10 = distinct !DISubprogram(name: "test_inline_strip_conflict", scope: !1, file: !1, line: 10, unit: !0)
161!11 = !DILocation(line: 11, scope: !10)
162!12 = distinct !DISubprogram(name: "test_noinline", scope: !1, file: !1, line: 12, unit: !0)
163!13 = !DILocation(line: 13, scope: !12)
164!14 = distinct !DISubprogram(name: "foo_inline1", scope: !1, file: !1, line: 11, unit: !0)
165!15 = distinct !DISubprogram(name: "foo_inline_strip.suffix", scope: !1, file: !1, line: 1, unit: !0)
166!16 = distinct !DISubprogram(name: "foo_inline_strip_conflict.suffix1", scope: !1, file: !1, line: 1, unit: !0)
167!17 = distinct !DISubprogram(name: "foo_inline_strip_conflict.suffix2", scope: !1, file: !1, line: 1, unit: !0)
168!18 = distinct !DISubprogram(name: "foo_inline_strip_conflict.suffix3", scope: !1, file: !1, line: 1, unit: !0)
169!19 = distinct !DISubprogram(name: "foo_inline2", scope: !1, file: !1, line: 19, unit: !0)
170!20 = distinct !DISubprogram(name: "foo_noinline", scope: !1, file: !1, line: 20, unit: !0)
171!21 = distinct !DISubprogram(name: "foo_direct", scope: !1, file: !1, line: 21, unit: !0)
172!22 = distinct !DISubprogram(name: "test_direct", scope: !1, file: !1, line: 22, unit: !0)
173!23 = !DILocation(line: 23, scope: !22)
Dehao Chene2a428b2017-06-08 20:11:57 +0000174!24 = distinct !DISubprogram(name: "test_norecursive_inline", scope: !1, file: !1, line: 12, unit: !0)
175!25 = !DILocation(line: 13, scope: !24)
Dehao Chenb6e60c82017-09-19 18:26:54 +0000176!26 = distinct !DISubprogram(name: "test_noinline_bitcast", scope: !1, file: !1, line: 12, unit: !0)
177!27 = !DILocation(line: 13, scope: !26)
178!28 = distinct !DISubprogram(name: "foo_direct_i32", scope: !1, file: !1, line: 11, unit: !0)