1 ; RUN: opt < %s -passes=globaldce -S | FileCheck %s
3 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5 declare dso_local noalias nonnull ptr @_Znwm(i64)
6 declare { ptr, i1 } @llvm.type.checked.load(ptr, i32, metadata)
8 ; %struct.A is a C++ struct with two virtual functions, A::foo and A::bar. The
9 ; !vcall_visibility metadata is set on the vtable, so we know that all virtual
10 ; calls through this vtable are visible and use the @llvm.type.checked.load
11 ; intrinsic. Function test_A makes a call to A::foo, but there is no call to
12 ; A::bar anywhere, so A::bar can be deleted, and its vtable slot replaced with
15 %struct.A = type { ptr }
17 ; The pointer to A::bar in the vtable can be removed, because it will never be
18 ; loaded. We replace it with null to keep the layout the same. Because it is at
19 ; the end of the vtable we could potentially shrink the vtable, but don't
21 ; CHECK: @_ZTV1A = internal unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr null, ptr @_ZN1A3fooEv, ptr null] }
22 @_ZTV1A = internal unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr null, ptr @_ZN1A3fooEv, ptr @_ZN1A3barEv] }, align 8, !type !0, !type !1, !type !2, !vcall_visibility !3
24 ; A::foo is called, so must be retained.
25 ; CHECK: define internal i32 @_ZN1A3fooEv(
26 define internal i32 @_ZN1A3fooEv(ptr nocapture readnone %this) {
31 ; A::bar is not used, so can be deleted.
32 ; CHECK-NOT: define internal i32 @_ZN1A3barEv(
33 define internal i32 @_ZN1A3barEv(ptr nocapture readnone %this) {
38 define dso_local i32 @test_A() {
40 %call = tail call ptr @_Znwm(i64 8)
41 store ptr getelementptr inbounds inrange(-16, 16) ({ [4 x ptr] }, ptr @_ZTV1A, i64 0, i32 0, i64 2), ptr %call, align 8
42 %0 = tail call { ptr, i1 } @llvm.type.checked.load(ptr getelementptr inbounds inrange(-16, 16) ({ [4 x ptr] }, ptr @_ZTV1A, i64 0, i32 0, i64 2), i32 0, metadata !"_ZTS1A"), !nosanitize !9
43 %1 = extractvalue { ptr, i1 } %0, 0, !nosanitize !9
44 %call1 = tail call i32 %1(ptr nonnull %call)
48 !llvm.module.flags = !{!4}
50 !0 = !{i64 16, !"_ZTS1A"}
51 !1 = !{i64 16, !"_ZTSM1AFivE.virtual"}
52 !2 = !{i64 24, !"_ZTSM1AFivE.virtual"}
54 !4 = !{i32 1, !"Virtual Function Elim", i32 1}