1 ; RUN: opt < %s -passes=globaldce -S | FileCheck %s
3 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
7 ; virtual int foo(int);
8 ; virtual int bar(float);
13 ; virtual int foo(int);
14 ; virtual int bar(float);
19 ; int A::foo(int) { return 1; }
20 ; int A::bar(float) { return 2; }
21 ; int B::foo(int) { return 3; }
22 ; int B::bar(float) { return 4; }
24 ; extern "C" int test(A *p, int (A::*q)(int)) { return (p->*q)(42); }
26 ; Member function pointers are tracked by the combination of their object type
27 ; and function type, which must both be compatible. Here, the call is through a
28 ; pointer of type "int (A::*q)(int)", so the call could be dispatched to A::foo
29 ; or B::foo. It can't be dispatched to A::bar or B::bar as the function pointer
30 ; does not match, so those can be removed.
32 %struct.A = type { ptr }
33 %struct.B = type { %struct.A }
35 ; CHECK: @_ZTV1A = internal unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr null, ptr @_ZN1A3fooEi, ptr null] }
36 @_ZTV1A = internal unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr null, ptr @_ZN1A3fooEi, ptr @_ZN1A3barEf] }, align 8, !type !0, !type !1, !type !2, !vcall_visibility !3
37 ; CHECK: @_ZTV1B = internal unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr null, ptr @_ZN1B3fooEi, ptr null] }
38 @_ZTV1B = internal unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr null, ptr @_ZN1B3fooEi, ptr @_ZN1B3barEf] }, align 8, !type !0, !type !1, !type !2, !type !4, !type !5, !type !6, !vcall_visibility !3
41 ; CHECK: define internal i32 @_ZN1A3fooEi(
42 define internal i32 @_ZN1A3fooEi(ptr nocapture readnone %this, i32) unnamed_addr #1 align 2 {
47 ; CHECK-NOT: define internal i32 @_ZN1A3barEf(
48 define internal i32 @_ZN1A3barEf(ptr nocapture readnone %this, float) unnamed_addr #1 align 2 {
53 ; CHECK: define internal i32 @_ZN1B3fooEi(
54 define internal i32 @_ZN1B3fooEi(ptr nocapture readnone %this, i32) unnamed_addr #1 align 2 {
59 ; CHECK-NOT: define internal i32 @_ZN1B3barEf(
60 define internal i32 @_ZN1B3barEf(ptr nocapture readnone %this, float) unnamed_addr #1 align 2 {
66 define hidden void @_ZN1AC2Ev(ptr nocapture %this) {
68 store ptr getelementptr inbounds inrange(-16, 16) ({ [4 x ptr] }, ptr @_ZTV1A, i64 0, i32 0, i64 2), ptr %this, align 8
72 define hidden void @_ZN1BC2Ev(ptr nocapture %this) {
74 store ptr getelementptr inbounds inrange(-16, 16) ({ [4 x ptr] }, ptr @_ZTV1B, i64 0, i32 0, i64 2), ptr %this, align 8
78 define hidden i32 @test(ptr %p, i64 %q.coerce0, i64 %q.coerce1) {
80 %0 = getelementptr inbounds i8, ptr %p, i64 %q.coerce1
81 %1 = and i64 %q.coerce0, 1
82 %memptr.isvirtual = icmp eq i64 %1, 0
83 br i1 %memptr.isvirtual, label %memptr.nonvirtual, label %memptr.virtual
85 memptr.virtual: ; preds = %entry
86 %vtable = load ptr, ptr %0, align 8
87 %2 = add i64 %q.coerce0, -1
88 %3 = getelementptr i8, ptr %vtable, i64 %2, !nosanitize !12
89 %4 = tail call { ptr, i1 } @llvm.type.checked.load(ptr %3, i32 0, metadata !"_ZTSM1AFiiE.virtual"), !nosanitize !12
90 %5 = extractvalue { ptr, i1 } %4, 0, !nosanitize !12
93 memptr.nonvirtual: ; preds = %entry
94 %memptr.nonvirtualfn = inttoptr i64 %q.coerce0 to ptr
97 memptr.end: ; preds = %memptr.nonvirtual, %memptr.virtual
98 %6 = phi ptr [ %5, %memptr.virtual ], [ %memptr.nonvirtualfn, %memptr.nonvirtual ]
99 %call = tail call i32 %6(ptr %0, i32 42)
103 declare { ptr, i1 } @llvm.type.checked.load(ptr, i32, metadata)
105 !llvm.module.flags = !{!7}
107 !0 = !{i64 16, !"_ZTS1A"}
108 !1 = !{i64 16, !"_ZTSM1AFiiE.virtual"}
109 !2 = !{i64 24, !"_ZTSM1AFifE.virtual"}
111 !4 = !{i64 16, !"_ZTS1B"}
112 !5 = !{i64 16, !"_ZTSM1BFiiE.virtual"}
113 !6 = !{i64 24, !"_ZTSM1BFifE.virtual"}
114 !7 = !{i32 1, !"Virtual Function Elim", i32 1}