1 ; RUN: opt -S -passes=wholeprogramdevirt -whole-program-visibility %s | FileCheck %s
3 target datalayout = "e-p:64:64"
4 target triple = "x86_64-unknown-linux-gnu"
6 @vt1 = constant [2 x ptr] [ptr @vf1a, ptr @vf1b], !type !0
7 @vt2 = constant [2 x ptr] [ptr @vf2a, ptr @vf2b], !type !0
9 @sink = external global i32
11 define i32 @vf1a(ptr %this, i32 %arg) {
12 store i32 %arg, ptr @sink
16 define i32 @vf2a(ptr %this, i32 %arg) {
17 store i32 %arg, ptr @sink
21 define i32 @vf1b(ptr %this, i32 %arg) {
25 define i32 @vf2b(ptr %this, i32 %arg) {
29 ; Test that we don't apply VCP if the virtual function body accesses memory,
30 ; even if the function returns a constant.
32 ; CHECK: define i32 @call1
33 define i32 @call1(ptr %obj) {
34 %vtable = load ptr, ptr %obj
35 %p = call i1 @llvm.type.test(ptr %vtable, metadata !"typeid")
36 call void @llvm.assume(i1 %p)
37 %fptr = load ptr, ptr %vtable
39 %result = call i32 %fptr(ptr %obj, i32 1)
43 ; Test that we can apply VCP regardless of the function attributes by analyzing
44 ; the function body itself.
46 ; CHECK: define i32 @call2
47 define i32 @call2(ptr %obj) {
48 %vtable = load ptr, ptr %obj
49 %p = call i1 @llvm.type.test(ptr %vtable, metadata !"typeid")
50 call void @llvm.assume(i1 %p)
51 %fptrptr = getelementptr [1 x ptr], ptr %vtable, i32 0, i32 1
52 %fptr = load ptr, ptr %fptrptr
53 %result = call i32 %fptr(ptr %obj, i32 1)
58 declare i1 @llvm.type.test(ptr, metadata)
59 declare void @llvm.assume(i1)
61 !0 = !{i32 0, !"typeid"}