blob: 5a4913d6358f5cdbfc450b983b0156c306895686 [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.
Dehao Chenc81483d2017-02-06 18:10:36 +000015define void @test_inline(i64* (i32*)*, i32* %x) !dbg !3 {
16 %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 Chen274df5e2017-01-31 17:49:37 +000027; CHECK: call
Dehao Chenc81483d2017-02-06 18:10:36 +000028 call i64* %3(i32* %x), !dbg !5
Dehao Chen274df5e2017-01-31 17:49:37 +000029 ret void
30}
31
32; CHECK-LABEL: @test_noinline
33; If the indirect call target is not available, we should not promote it.
34define void @test_noinline(void ()*) !dbg !3 {
35 %2 = alloca void ()*
36 store void ()* %0, void ()** %2
37 %3 = load void ()*, void ()** %2
38; CHECK-NOT: icmp
39; CHECK: call
40 call void %3(), !dbg !5
41 ret void
42}
43
Dehao Chenc81483d2017-02-06 18:10:36 +000044@x = global i32 0, align 4
45
Dehao Chen2c7ca9b2017-04-13 19:52:10 +000046define i32* @foo_inline1(i32* %x) !dbg !3 {
47 ret i32* %x
48}
49
50define i32* @foo_inline2(i32* %x) !dbg !3 {
Dehao Chenc81483d2017-02-06 18:10:36 +000051 ret i32* %x
Dehao Chen274df5e2017-01-31 17:49:37 +000052}
53
54define i32 @foo_noinline(i32 %x) !dbg !3 {
55 ret i32 %x
56}
57
Dehao Chen4a9dd702017-02-06 23:33:15 +000058define void @foo_direct() !dbg !3 {
59 ret void
60}
61
62; CHECK-LABEL: @test_direct
63; We should not promote a direct call.
64define void @test_direct() !dbg !3 {
65; CHECK-NOT: icmp
66; CHECK: call
67 call void @foo_alias(), !dbg !5
68 ret void
69}
70
71@foo_alias = alias void (), void ()* @foo_direct
72
Dehao Chen77079002017-01-20 22:56:07 +000073!llvm.dbg.cu = !{!0}
74!llvm.module.flags = !{!2}
75
76!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1)
77!1 = !DIFile(filename: "test.cc", directory: "/")
78!2 = !{i32 2, !"Debug Info Version", i32 3}
79!3 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 1, unit: !0)
80!4 = !DILocation(line: 5, scope: !3)
Dehao Chen274df5e2017-01-31 17:49:37 +000081!5 = !DILocation(line: 6, scope: !3)
Dehao Chen77079002017-01-20 22:56:07 +000082; CHECK: ![[PROF]] = !{!"VP", i32 0, i64 3457, i64 9191153033785521275, i64 2059, i64 -1069303473483922844, i64 1398}