Dehao Chen | 7707900 | 2017-01-20 22:56:07 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/indirect-call.prof -S | FileCheck %s |
| 2 | |
Dehao Chen | 274df5e | 2017-01-31 17:49:37 +0000 | [diff] [blame] | 3 | ; CHECK-LABEL: @test |
Dehao Chen | 7707900 | 2017-01-20 22:56:07 +0000 | [diff] [blame] | 4 | define 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 Chen | 274df5e | 2017-01-31 17:49:37 +0000 | [diff] [blame] | 13 | ; CHECK-LABEL: @test_inline |
| 14 | ; If the indirect call is promoted and inlined in profile, we should promote and inline it. |
Adrian Prantl | defc99a | 2017-05-04 16:24:31 +0000 | [diff] [blame] | 15 | define void @test_inline(i64* (i32*)*, i32* %x) !dbg !6 { |
Dehao Chen | c81483d | 2017-02-06 18:10:36 +0000 | [diff] [blame] | 16 | %2 = alloca i64* (i32*)* |
| 17 | store i64* (i32*)* %0, i64* (i32*)** %2 |
| 18 | %3 = load i64* (i32*)*, i64* (i32*)** %2 |
Dehao Chen | 2c7ca9b | 2017-04-13 19:52:10 +0000 | [diff] [blame] | 19 | ; CHECK: icmp {{.*}} @foo_inline2 |
Dehao Chen | 274df5e | 2017-01-31 17:49:37 +0000 | [diff] [blame] | 20 | ; CHECK: if.true.direct_targ: |
| 21 | ; CHECK-NOT: call |
| 22 | ; CHECK: if.false.orig_indirect: |
Dehao Chen | 2c7ca9b | 2017-04-13 19:52:10 +0000 | [diff] [blame] | 23 | ; CHECK: icmp {{.*}} @foo_inline1 |
| 24 | ; CHECK: if.true.direct_targ1: |
| 25 | ; CHECK-NOT: call |
| 26 | ; CHECK: if.false.orig_indirect2: |
Dehao Chen | 274df5e | 2017-01-31 17:49:37 +0000 | [diff] [blame] | 27 | ; CHECK: call |
Adrian Prantl | defc99a | 2017-05-04 16:24:31 +0000 | [diff] [blame] | 28 | call i64* %3(i32* %x), !dbg !7 |
Dehao Chen | 274df5e | 2017-01-31 17:49:37 +0000 | [diff] [blame] | 29 | ret void |
| 30 | } |
| 31 | |
Dehao Chen | 1ea8bd8 | 2017-04-17 22:23:05 +0000 | [diff] [blame] | 32 | ; 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 Prantl | defc99a | 2017-05-04 16:24:31 +0000 | [diff] [blame] | 35 | define void @test_inline_strip(i64* (i32*)*, i32* %x) !dbg !8 { |
Dehao Chen | 1ea8bd8 | 2017-04-17 22:23:05 +0000 | [diff] [blame] | 36 | %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 Prantl | defc99a | 2017-05-04 16:24:31 +0000 | [diff] [blame] | 44 | call i64* %3(i32* %x), !dbg !9 |
Dehao Chen | 1ea8bd8 | 2017-04-17 22:23:05 +0000 | [diff] [blame] | 45 | 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 Prantl | defc99a | 2017-05-04 16:24:31 +0000 | [diff] [blame] | 51 | define void @test_inline_strip_conflict(i64* (i32*)*, i32* %x) !dbg !10 { |
Dehao Chen | 1ea8bd8 | 2017-04-17 22:23:05 +0000 | [diff] [blame] | 52 | %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 Prantl | defc99a | 2017-05-04 16:24:31 +0000 | [diff] [blame] | 56 | call i64* %3(i32* %x), !dbg !11 |
Dehao Chen | 1ea8bd8 | 2017-04-17 22:23:05 +0000 | [diff] [blame] | 57 | ret void |
| 58 | } |
| 59 | |
Dehao Chen | 274df5e | 2017-01-31 17:49:37 +0000 | [diff] [blame] | 60 | ; CHECK-LABEL: @test_noinline |
| 61 | ; If the indirect call target is not available, we should not promote it. |
Adrian Prantl | defc99a | 2017-05-04 16:24:31 +0000 | [diff] [blame] | 62 | define void @test_noinline(void ()*) !dbg !12 { |
Dehao Chen | 274df5e | 2017-01-31 17:49:37 +0000 | [diff] [blame] | 63 | %2 = alloca void ()* |
| 64 | store void ()* %0, void ()** %2 |
| 65 | %3 = load void ()*, void ()** %2 |
| 66 | ; CHECK-NOT: icmp |
| 67 | ; CHECK: call |
Adrian Prantl | defc99a | 2017-05-04 16:24:31 +0000 | [diff] [blame] | 68 | call void %3(), !dbg !13 |
Dehao Chen | 274df5e | 2017-01-31 17:49:37 +0000 | [diff] [blame] | 69 | ret void |
| 70 | } |
| 71 | |
Dehao Chen | c81483d | 2017-02-06 18:10:36 +0000 | [diff] [blame] | 72 | @x = global i32 0, align 4 |
| 73 | |
Adrian Prantl | defc99a | 2017-05-04 16:24:31 +0000 | [diff] [blame] | 74 | define i32* @foo_inline1(i32* %x) !dbg !14 { |
Dehao Chen | 2c7ca9b | 2017-04-13 19:52:10 +0000 | [diff] [blame] | 75 | ret i32* %x |
| 76 | } |
| 77 | |
Adrian Prantl | defc99a | 2017-05-04 16:24:31 +0000 | [diff] [blame] | 78 | define i32* @foo_inline_strip.suffix(i32* %x) !dbg !15 { |
Dehao Chen | 1ea8bd8 | 2017-04-17 22:23:05 +0000 | [diff] [blame] | 79 | ret i32* %x |
| 80 | } |
| 81 | |
Adrian Prantl | defc99a | 2017-05-04 16:24:31 +0000 | [diff] [blame] | 82 | define i32* @foo_inline_strip_conflict.suffix1(i32* %x) !dbg !16 { |
Dehao Chen | 1ea8bd8 | 2017-04-17 22:23:05 +0000 | [diff] [blame] | 83 | ret i32* %x |
| 84 | } |
| 85 | |
Adrian Prantl | defc99a | 2017-05-04 16:24:31 +0000 | [diff] [blame] | 86 | define i32* @foo_inline_strip_conflict.suffix2(i32* %x) !dbg !17 { |
Dehao Chen | 1ea8bd8 | 2017-04-17 22:23:05 +0000 | [diff] [blame] | 87 | ret i32* %x |
| 88 | } |
| 89 | |
Adrian Prantl | defc99a | 2017-05-04 16:24:31 +0000 | [diff] [blame] | 90 | define i32* @foo_inline_strip_conflict.suffix3(i32* %x) !dbg !18 { |
Dehao Chen | 1ea8bd8 | 2017-04-17 22:23:05 +0000 | [diff] [blame] | 91 | ret i32* %x |
| 92 | } |
| 93 | |
Adrian Prantl | defc99a | 2017-05-04 16:24:31 +0000 | [diff] [blame] | 94 | define i32* @foo_inline2(i32* %x) !dbg !19 { |
Dehao Chen | c81483d | 2017-02-06 18:10:36 +0000 | [diff] [blame] | 95 | ret i32* %x |
Dehao Chen | 274df5e | 2017-01-31 17:49:37 +0000 | [diff] [blame] | 96 | } |
| 97 | |
Adrian Prantl | defc99a | 2017-05-04 16:24:31 +0000 | [diff] [blame] | 98 | define i32 @foo_noinline(i32 %x) !dbg !20 { |
Dehao Chen | 274df5e | 2017-01-31 17:49:37 +0000 | [diff] [blame] | 99 | ret i32 %x |
| 100 | } |
| 101 | |
Adrian Prantl | defc99a | 2017-05-04 16:24:31 +0000 | [diff] [blame] | 102 | define void @foo_direct() !dbg !21 { |
Dehao Chen | 4a9dd70 | 2017-02-06 23:33:15 +0000 | [diff] [blame] | 103 | ret void |
| 104 | } |
| 105 | |
| 106 | ; CHECK-LABEL: @test_direct |
| 107 | ; We should not promote a direct call. |
Adrian Prantl | defc99a | 2017-05-04 16:24:31 +0000 | [diff] [blame] | 108 | define void @test_direct() !dbg !22 { |
Dehao Chen | 4a9dd70 | 2017-02-06 23:33:15 +0000 | [diff] [blame] | 109 | ; CHECK-NOT: icmp |
| 110 | ; CHECK: call |
Adrian Prantl | defc99a | 2017-05-04 16:24:31 +0000 | [diff] [blame] | 111 | call void @foo_alias(), !dbg !23 |
Dehao Chen | 4a9dd70 | 2017-02-06 23:33:15 +0000 | [diff] [blame] | 112 | ret void |
| 113 | } |
| 114 | |
| 115 | @foo_alias = alias void (), void ()* @foo_direct |
| 116 | |
Dehao Chen | 7707900 | 2017-01-20 22:56:07 +0000 | [diff] [blame] | 117 | !llvm.dbg.cu = !{!0} |
| 118 | !llvm.module.flags = !{!2} |
| 119 | |
| 120 | !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1) |
| 121 | !1 = !DIFile(filename: "test.cc", directory: "/") |
| 122 | !2 = !{i32 2, !"Debug Info Version", i32 3} |
Adrian Prantl | defc99a | 2017-05-04 16:24:31 +0000 | [diff] [blame] | 123 | !3 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 3, unit: !0) |
| 124 | !4 = !DILocation(line: 4, scope: !3) |
Dehao Chen | 274df5e | 2017-01-31 17:49:37 +0000 | [diff] [blame] | 125 | !5 = !DILocation(line: 6, scope: !3) |
Dehao Chen | 7707900 | 2017-01-20 22:56:07 +0000 | [diff] [blame] | 126 | ; CHECK: ![[PROF]] = !{!"VP", i32 0, i64 3457, i64 9191153033785521275, i64 2059, i64 -1069303473483922844, i64 1398} |
Adrian Prantl | defc99a | 2017-05-04 16:24:31 +0000 | [diff] [blame] | 127 | !6 = distinct !DISubprogram(name: "test_inline", scope: !1, file: !1, line: 6, unit: !0) |
| 128 | !7 = !DILocation(line: 7, scope: !6) |
| 129 | !8 = distinct !DISubprogram(name: "test_inline_strip", scope: !1, file: !1, line: 8, unit: !0) |
| 130 | !9 = !DILocation(line: 9, scope: !8) |
| 131 | !10 = distinct !DISubprogram(name: "test_inline_strip_conflict", scope: !1, file: !1, line: 10, unit: !0) |
| 132 | !11 = !DILocation(line: 11, scope: !10) |
| 133 | !12 = distinct !DISubprogram(name: "test_noinline", scope: !1, file: !1, line: 12, unit: !0) |
| 134 | !13 = !DILocation(line: 13, scope: !12) |
| 135 | !14 = distinct !DISubprogram(name: "foo_inline1", scope: !1, file: !1, line: 11, unit: !0) |
| 136 | !15 = distinct !DISubprogram(name: "foo_inline_strip.suffix", scope: !1, file: !1, line: 1, unit: !0) |
| 137 | !16 = distinct !DISubprogram(name: "foo_inline_strip_conflict.suffix1", scope: !1, file: !1, line: 1, unit: !0) |
| 138 | !17 = distinct !DISubprogram(name: "foo_inline_strip_conflict.suffix2", scope: !1, file: !1, line: 1, unit: !0) |
| 139 | !18 = distinct !DISubprogram(name: "foo_inline_strip_conflict.suffix3", scope: !1, file: !1, line: 1, unit: !0) |
| 140 | !19 = distinct !DISubprogram(name: "foo_inline2", scope: !1, file: !1, line: 19, unit: !0) |
| 141 | !20 = distinct !DISubprogram(name: "foo_noinline", scope: !1, file: !1, line: 20, unit: !0) |
| 142 | !21 = distinct !DISubprogram(name: "foo_direct", scope: !1, file: !1, line: 21, unit: !0) |
| 143 | !22 = distinct !DISubprogram(name: "test_direct", scope: !1, file: !1, line: 22, unit: !0) |
| 144 | !23 = !DILocation(line: 23, scope: !22) |