2 ; RUN: opt < %s -passes=globaldce -S | FileCheck %s
4 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
8 ; virtual int foo(int);
9 ; virtual int bar(float);
14 ; virtual int foo(int);
15 ; virtual int bar(float);
20 ; int A::foo(int) { return 1; }
21 ; int A::bar(float) { return 2; }
22 ; int B::foo(int) { return 3; }
23 ; int B::bar(float) { return 4; }
25 ; extern "C" int test(B *p, int (B::*q)(int)) { return (p->*q)(42); }
27 ; Member function pointers are tracked by the combination of their object type
28 ; and function type, which must both be compatible. Here, the call is through a
29 ; pointer of type "int (B::*q)(int)", so the call could only be dispatched to
30 ; B::foo. It can't be dispatched to A::bar or B::bar as the function pointer
31 ; does not match, and it can't be dispatched to A::foo as the object type
32 ; doesn't match, so those can be removed.
34 %struct.A = type { ptr }
35 %struct.B = type { %struct.A }
37 ; CHECK: @_ZTV1A = internal unnamed_addr constant { [4 x ptr] } zeroinitializer
38 @_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
39 ; CHECK: @_ZTV1B = internal unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr null, ptr @_ZN1B3fooEi, ptr null] }
40 @_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
43 ; CHECK-NOT: define internal i32 @_ZN1A3fooEi(
44 define internal i32 @_ZN1A3fooEi(ptr nocapture readnone %this, i32) unnamed_addr #1 align 2 {
49 ; CHECK-NOT: define internal i32 @_ZN1A3barEf(
50 define internal i32 @_ZN1A3barEf(ptr nocapture readnone %this, float) unnamed_addr #1 align 2 {
55 ; CHECK: define internal i32 @_ZN1B3fooEi(
56 define internal i32 @_ZN1B3fooEi(ptr nocapture readnone %this, i32) unnamed_addr #1 align 2 {
61 ; CHECK-NOT: define internal i32 @_ZN1B3barEf(
62 define internal i32 @_ZN1B3barEf(ptr nocapture readnone %this, float) unnamed_addr #1 align 2 {
68 define hidden void @_ZN1AC2Ev(ptr nocapture %this) {
70 store ptr getelementptr inbounds inrange(-16, 16) ({ [4 x ptr] }, ptr @_ZTV1A, i64 0, i32 0, i64 2), ptr %this, align 8
74 define hidden void @_ZN1BC2Ev(ptr nocapture %this) {
76 store ptr getelementptr inbounds inrange(-16, 16) ({ [4 x ptr] }, ptr @_ZTV1B, i64 0, i32 0, i64 2), ptr %this, align 8
80 define hidden i32 @test(ptr %p, i64 %q.coerce0, i64 %q.coerce1) {
82 %0 = getelementptr inbounds i8, ptr %p, i64 %q.coerce1
83 %1 = and i64 %q.coerce0, 1
84 %memptr.isvirtual = icmp eq i64 %1, 0
85 br i1 %memptr.isvirtual, label %memptr.nonvirtual, label %memptr.virtual
87 memptr.virtual: ; preds = %entry
88 %vtable = load ptr, ptr %0, align 8
89 %2 = add i64 %q.coerce0, -1
90 %3 = getelementptr i8, ptr %vtable, i64 %2, !nosanitize !12
91 %4 = tail call { ptr, i1 } @llvm.type.checked.load(ptr %3, i32 0, metadata !"_ZTSM1BFiiE.virtual"), !nosanitize !12
92 %5 = extractvalue { ptr, i1 } %4, 0, !nosanitize !12
95 memptr.nonvirtual: ; preds = %entry
96 %memptr.nonvirtualfn = inttoptr i64 %q.coerce0 to ptr
99 memptr.end: ; preds = %memptr.nonvirtual, %memptr.virtual
100 %6 = phi ptr [ %5, %memptr.virtual ], [ %memptr.nonvirtualfn, %memptr.nonvirtual ]
101 %call = tail call i32 %6(ptr %0, i32 42)
105 declare { ptr, i1 } @llvm.type.checked.load(ptr, i32, metadata)
107 !llvm.module.flags = !{!7}
109 !0 = !{i64 16, !"_ZTS1A"}
110 !1 = !{i64 16, !"_ZTSM1AFiiE.virtual"}
111 !2 = !{i64 24, !"_ZTSM1AFifE.virtual"}
113 !4 = !{i64 16, !"_ZTS1B"}
114 !5 = !{i64 16, !"_ZTSM1BFiiE.virtual"}
115 !6 = !{i64 24, !"_ZTSM1BFifE.virtual"}
116 !7 = !{i32 1, !"Virtual Function Elim", i32 1}