Home | History | Annotate | Download | only in SampleProfile
      1 ; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/indirect-call.prof -S | FileCheck %s
      2 
      3 ; CHECK-LABEL: @test
      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 
     13 ; CHECK-LABEL: @test_inline
     14 ; If the indirect call is promoted and inlined in profile, we should promote and inline it.
     15 define void @test_inline(i64* (i32*)*, i32* %x) !dbg !6 {
     16   %2 = alloca i64* (i32*)*
     17   store i64* (i32*)* %0, i64* (i32*)** %2
     18   %3 = load i64* (i32*)*, i64* (i32*)** %2
     19 ; CHECK: icmp {{.*}} @foo_inline2
     20 ; CHECK: br {{.*}} !prof ![[BR1:[0-9]+]]
     21 ; CHECK: if.true.direct_targ:
     22 ; CHECK-NOT: call
     23 ; CHECK: if.false.orig_indirect:
     24 ; CHECK: icmp {{.*}} @foo_inline1
     25 ; CHECK: br {{.*}} !prof ![[BR2:[0-9]+]]
     26 ; CHECK: if.true.direct_targ1:
     27 ; CHECK-NOT: call
     28 ; CHECK: if.false.orig_indirect2:
     29 ; CHECK: call {{.*}} !prof ![[VP:[0-9]+]]
     30   call i64* %3(i32* %x), !dbg !7
     31   ret void
     32 }
     33 
     34 ; 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.
     37 define void @test_inline_strip(i64* (i32*)*, i32* %x) !dbg !8 {
     38   %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
     46   call i64* %3(i32* %x), !dbg !9
     47   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.
     53 define void @test_inline_strip_conflict(i64* (i32*)*, i32* %x) !dbg !10 {
     54   %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:
     58   call i64* %3(i32* %x), !dbg !11
     59   ret void
     60 }
     61 
     62 ; CHECK-LABEL: @test_noinline
     63 ; If the indirect call target is not available, we should not promote it.
     64 define void @test_noinline(void ()*) !dbg !12 {
     65   %2 = alloca void ()*
     66   store void ()* %0, void ()** %2
     67   %3 = load void ()*, void ()** %2
     68 ; CHECK-NOT: icmp
     69 ; CHECK: call
     70   call void %3(), !dbg !13
     71   ret void
     72 }
     73 
     74 ; CHECK-LABEL: @test_noinline_bitcast
     75 ; If the indirect call has been promoted to a direct call with bitcast,
     76 ; do not inline it.
     77 define 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 
     87 ; CHECK-LABEL: @test_norecursive_inline
     88 ; If the indirect call target is the caller, we should not promote it.
     89 define 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 
     97 define 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.
    105 define 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 
    115 then:
    116   %3 = tail call i32* %0(i32* %2), !dbg !32
    117   ret i32* %3
    118 
    119 else:
    120   ret i32* null
    121 }
    122 
    123 @x = global i32 0, align 4
    124 @y = global void ()* null, align 8
    125 
    126 define i32* @foo_inline1(i32* %x) !dbg !14 {
    127   ret i32* %x
    128 }
    129 
    130 define i32* @foo_inline_strip.suffix(i32* %x) !dbg !15 {
    131   ret i32* %x
    132 }
    133 
    134 define i32* @foo_inline_strip_conflict.suffix1(i32* %x) !dbg !16 {
    135   ret i32* %x
    136 }
    137 
    138 define i32* @foo_inline_strip_conflict.suffix2(i32* %x) !dbg !17 {
    139   ret i32* %x
    140 }
    141 
    142 define i32* @foo_inline_strip_conflict.suffix3(i32* %x) !dbg !18 {
    143   ret i32* %x
    144 }
    145 
    146 define i32* @foo_inline2(i32* %x) !dbg !19 {
    147   ret i32* %x
    148 }
    149 
    150 define i32 @foo_noinline(i32 %x) !dbg !20 {
    151   ret i32 %x
    152 }
    153 
    154 define void @foo_direct() !dbg !21 {
    155   ret void
    156 }
    157 
    158 define i32 @foo_direct_i32() !dbg !28 {
    159   ret i32 0;
    160 }
    161 
    162 ; CHECK-LABEL: @test_direct
    163 ; We should not promote a direct call.
    164 define void @test_direct() !dbg !22 {
    165 ; CHECK-NOT: icmp
    166 ; CHECK: call
    167   call void @foo_alias(), !dbg !23
    168   ret void
    169 }
    170 
    171 @foo_alias = alias void (), void ()* @foo_direct
    172 
    173 !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}
    179 !3 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 3, unit: !0)
    180 !4 = !DILocation(line: 4, scope: !3)
    181 !5 = !DILocation(line: 6, scope: !3)
    182 ; CHECK: ![[PROF]] = !{!"VP", i32 0, i64 3457, i64 9191153033785521275, i64 2059, i64 -1069303473483922844, i64 1398}
    183 ; CHECK: ![[BR1]] = !{!"branch_weights", i32 4000, i32 4000}
    184 ; CHECK: ![[BR2]] = !{!"branch_weights", i32 3000, i32 1000}
    185 ; CHECK: ![[VP]] = !{!"VP", i32 0, i64 8000, i64 -6391416044382067764, i64 1000}
    186 !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)
    204 !24 = distinct !DISubprogram(name: "test_norecursive_inline", scope: !1, file: !1, line: 12, unit: !0)
    205 !25 = !DILocation(line: 13, scope: !24)
    206 !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)
    209 !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)
    213