1 ; REQUIRES: x86-registered-target
3 ; Test devirtualization through the thin link and backend, when vtables
4 ; have vcall_visibility metadata with public visibility.
7 ; Generate unsplit module with summary for ThinLTO index-based WPD.
8 ; RUN: opt -thinlto-bc -o %t2.o %s
9 ; RUN: llvm-lto2 run %t2.o -save-temps -pass-remarks=. \
11 ; RUN: -r=%t2.o,test,px \
12 ; RUN: -r=%t2.o,_ZN1A1nEi,p \
13 ; RUN: -r=%t2.o,_ZN1B1fEi,p \
14 ; RUN: -r=%t2.o,_ZN1C1fEi,p \
15 ; RUN: -r=%t2.o,_ZN1D1mEi,p \
16 ; RUN: -r=%t2.o,_ZTV1B,px \
17 ; RUN: -r=%t2.o,_ZTV1C,px \
18 ; RUN: -r=%t2.o,_ZTV1D,px 2>&1 | FileCheck %s --check-prefix=REMARK
19 ; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
22 ; Generate split module with summary for hybrid Thin/Regular LTO WPD.
23 ; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t.o %s
24 ; RUN: llvm-lto2 run %t.o -save-temps -pass-remarks=. \
26 ; RUN: -r=%t.o,test,px \
27 ; RUN: -r=%t.o,_ZN1A1nEi,p \
28 ; RUN: -r=%t.o,_ZN1B1fEi,p \
29 ; RUN: -r=%t.o,_ZN1C1fEi,p \
30 ; RUN: -r=%t.o,_ZN1D1mEi,p \
31 ; RUN: -r=%t.o,_ZTV1B, \
32 ; RUN: -r=%t.o,_ZTV1C, \
33 ; RUN: -r=%t.o,_ZTV1D, \
34 ; RUN: -r=%t.o,_ZN1A1nEi, \
35 ; RUN: -r=%t.o,_ZN1B1fEi, \
36 ; RUN: -r=%t.o,_ZN1C1fEi, \
37 ; RUN: -r=%t.o,_ZN1D1mEi, \
38 ; RUN: -r=%t.o,_ZTV1B,px \
39 ; RUN: -r=%t.o,_ZTV1C,px \
40 ; RUN: -r=%t.o,_ZTV1D,px 2>&1 | FileCheck %s --check-prefix=REMARK --dump-input=fail
41 ; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
44 ; RUN: opt -o %t4.o %s
45 ; RUN: llvm-lto2 run %t4.o -save-temps -pass-remarks=. \
46 ; RUN: -whole-program-visibility \
48 ; RUN: -r=%t4.o,test,px \
49 ; RUN: -r=%t4.o,_ZN1A1nEi,p \
50 ; RUN: -r=%t4.o,_ZN1B1fEi,p \
51 ; RUN: -r=%t4.o,_ZN1C1fEi,p \
52 ; RUN: -r=%t4.o,_ZN1D1mEi,p \
53 ; RUN: -r=%t4.o,_ZTV1B,px \
54 ; RUN: -r=%t4.o,_ZTV1C,px \
55 ; RUN: -r=%t4.o,_ZTV1D,px 2>&1 | FileCheck %s --check-prefix=REMARK
56 ; RUN: llvm-dis %t5.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
58 ; REMARK-DAG: single-impl: devirtualized a call to _ZN1A1nEi
59 ; REMARK-DAG: single-impl: devirtualized a call to _ZN1D1mEi
61 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
62 target triple = "x86_64-grtev4-linux-gnu"
64 %struct.A = type { ptr }
65 %struct.B = type { %struct.A }
66 %struct.C = type { %struct.A }
67 %struct.D = type { ptr }
69 @_ZTV1B = constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr undef, ptr @_ZN1B1fEi, ptr @_ZN1A1nEi] }, !type !0, !type !1, !vcall_visibility !5
70 @_ZTV1C = constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr undef, ptr @_ZN1C1fEi, ptr @_ZN1A1nEi] }, !type !0, !type !2, !vcall_visibility !5
71 @_ZTV1D = constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr undef, ptr @_ZN1D1mEi] }, !type !3, !vcall_visibility !5
74 ; CHECK-IR-LABEL: define {{(noundef )?}}i32 @test
75 define i32 @test(ptr %obj, ptr %obj2, i32 %a) {
77 %vtable = load ptr, ptr %obj
78 %p = call i1 @llvm.type.test(ptr %vtable, metadata !"_ZTS1A")
79 call void @llvm.assume(i1 %p)
80 %fptrptr = getelementptr ptr, ptr %vtable, i32 1
81 %fptr1 = load ptr, ptr %fptrptr, align 8
83 ; Check that the call was devirtualized.
84 ; CHECK-IR: %call = tail call i32 @_ZN1A1nEi
85 %call = tail call i32 %fptr1(ptr nonnull %obj, i32 %a)
87 %fptr22 = load ptr, ptr %vtable, align 8
89 ; We still have to call it as virtual.
90 ; CHECK-IR: %call3 = tail call i32 %fptr22
91 %call3 = tail call i32 %fptr22(ptr nonnull %obj, i32 %call)
93 %vtable2 = load ptr, ptr %obj2
94 %p2 = call i1 @llvm.type.test(ptr %vtable2, metadata !4)
95 call void @llvm.assume(i1 %p2)
97 %fptr33 = load ptr, ptr %vtable2, align 8
99 ; Check that the call was devirtualized.
100 ; CHECK-IR: %call4 = tail call i32 @_ZN1D1mEi
101 %call4 = tail call i32 %fptr33(ptr nonnull %obj2, i32 %call3)
104 ; CHECK-IR-LABEL: ret i32
107 declare i1 @llvm.type.test(ptr, metadata)
108 declare void @llvm.assume(i1)
110 define i32 @_ZN1B1fEi(ptr %this, i32 %a) #0 {
114 define i32 @_ZN1A1nEi(ptr %this, i32 %a) #0 {
118 define i32 @_ZN1C1fEi(ptr %this, i32 %a) #0 {
122 define i32 @_ZN1D1mEi(ptr %this, i32 %a) #0 {
126 ; Make sure we don't inline or otherwise optimize out the direct calls.
127 attributes #0 = { noinline optnone }
129 !0 = !{i64 16, !"_ZTS1A"}
130 !1 = !{i64 16, !"_ZTS1B"}
131 !2 = !{i64 16, !"_ZTS1C"}