1 ; -stats requires asserts
4 ; RUN: opt -S -passes=wholeprogramdevirt -whole-program-visibility -pass-remarks=wholeprogramdevirt -stats %s 2>&1 | FileCheck %s
6 target datalayout = "e-p:64:64"
7 target triple = "x86_64-unknown-linux-gnu"
9 ; CHECK: remark: devirt-single.cc:30:32: single-impl: devirtualized a call to vf
10 ; CHECK: remark: devirt-single.cc:41:32: single-impl: devirtualized a call to vf
11 ; CHECK: remark: devirt-single.cc:51:32: single-impl: devirtualized a call to vf
12 ; CHECK: remark: devirt-single.cc:13:0: devirtualized vf
13 ; CHECK-NOT: devirtualized
15 @vt1 = constant [1 x ptr] [ptr @vf], !type !8
16 @vt2 = constant [1 x ptr] [ptr @vf], !type !8
18 define void @vf(ptr %this) #0 !dbg !7 {
22 ; CHECK: define void @call
23 define void @call(ptr %obj) #1 !dbg !5 {
24 %vtable = load ptr, ptr %obj
25 %p = call i1 @llvm.type.test(ptr %vtable, metadata !"typeid")
26 call void @llvm.assume(i1 %p)
27 %fptr = load ptr, ptr %vtable
28 ; CHECK: call void @vf(
29 call void %fptr(ptr %obj), !dbg !6
33 declare ptr @llvm.load.relative.i32(ptr, i32)
35 @vt3 = private unnamed_addr constant [1 x i32] [
36 i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @vf to i64), i64 ptrtoint (ptr @vt3 to i64)) to i32)
39 ; CHECK: define void @call2
40 define void @call2(ptr %obj) #1 !dbg !9 {
41 %vtable = load ptr, ptr %obj
42 %p = call i1 @llvm.type.test(ptr %vtable, metadata !"typeid2")
43 call void @llvm.assume(i1 %p)
44 %fptr = call ptr @llvm.load.relative.i32(ptr %vtable, i32 0)
45 ; CHECK: call void @vf(
46 call void %fptr(ptr %obj), !dbg !10
50 @_ZTV1A.local = private unnamed_addr constant { [3 x i32] } { [3 x i32] [
51 i32 0, ; offset to top
53 i32 trunc (i64 sub (i64 ptrtoint (ptr dso_local_equivalent @vf to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [3 x i32] }, ptr @_ZTV1A.local, i32 0, i32 0, i32 2) to i64)) to i32) ; vfunc offset
54 ] }, align 4, !type !14
56 ; CHECK: define void @call3
57 define void @call3(ptr %obj) #1 !dbg !12 {
58 %vtable = load ptr, ptr %obj
59 %p = call i1 @llvm.type.test(ptr %vtable, metadata !"typeid3")
60 call void @llvm.assume(i1 %p)
61 %fptr = call ptr @llvm.load.relative.i32(ptr %vtable, i32 8)
62 ; CHECK: call void @vf(
63 call void %fptr(ptr %obj), !dbg !13
68 declare i1 @llvm.type.test(ptr, metadata)
69 declare void @llvm.assume(i1)
72 !llvm.module.flags = !{!2, !3}
75 !0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 4.0.0 (trunk 278098)", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
76 !1 = !DIFile(filename: "devirt-single.cc", directory: ".")
77 !2 = !{i32 2, !"Dwarf Version", i32 4}
78 !3 = !{i32 2, !"Debug Info Version", i32 3}
79 !4 = !{!"clang version 4.0.0 (trunk 278098)"}
80 !5 = distinct !DISubprogram(name: "call", linkageName: "_Z4callPv", scope: !1, file: !1, line: 29, isLocal: false, isDefinition: true, scopeLine: 9, flags: DIFlagPrototyped, isOptimized: false, unit: !0)
81 !6 = !DILocation(line: 30, column: 32, scope: !5)
82 !7 = distinct !DISubprogram(name: "vf", linkageName: "_ZN3vt12vfEv", scope: !1, file: !1, line: 13, isLocal: false, isDefinition: true, scopeLine: 13, flags: DIFlagPrototyped, isOptimized: false, unit: !0)
83 !8 = !{i32 0, !"typeid"}
85 !9 = distinct !DISubprogram(name: "call2", linkageName: "_Z5call2Pv", scope: !1, file: !1, line: 40, isLocal: false, isDefinition: true, scopeLine: 9, flags: DIFlagPrototyped, isOptimized: false, unit: !0)
86 !10 = !DILocation(line: 41, column: 32, scope: !9)
87 !11 = !{i32 0, !"typeid2"}
89 !12 = distinct !DISubprogram(name: "call3", linkageName: "_Z5call3Pv", scope: !1, file: !1, line: 50, isLocal: false, isDefinition: true, scopeLine: 9, flags: DIFlagPrototyped, isOptimized: false, unit: !0)
90 !13 = !DILocation(line: 51, column: 32, scope: !12)
91 !14 = !{i32 0, !"typeid3"}
93 ; CHECK: 1 wholeprogramdevirt - Number of whole program devirtualization targets
94 ; CHECK: 3 wholeprogramdevirt - Number of single implementation devirtualizations