1; Tests that VFE is not performed when the Virtual Function Elim metadata set 2; to 0. This is the same as virtual-functions.ll otherwise. 3; RUN: opt < %s -passes=globaldce -S | FileCheck %s 4 5target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 6 7declare dso_local noalias nonnull ptr @_Znwm(i64) 8declare { ptr, i1 } @llvm.type.checked.load(ptr, i32, metadata) 9 10; %struct.A is a C++ struct with two virtual functions, A::foo and A::bar. The 11; !vcall_visibility metadata is set on the vtable, so we know that all virtual 12; calls through this vtable are visible and use the @llvm.type.checked.load 13; intrinsic. Function test_A makes a call to A::foo, but there is no call to 14; A::bar anywhere, so A::bar can be deleted, and its vtable slot replaced with 15; null. 16; However, with the metadata set to 0 we should not perform this VFE. 17 18%struct.A = type { ptr } 19 20; We should retain @_ZN1A3barEv in the vtable. 21; CHECK: @_ZTV1A = internal unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr null, ptr @_ZN1A3fooEv, ptr @_ZN1A3barEv] } 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 23 24; A::foo is called, so must be retained. 25; CHECK: define internal i32 @_ZN1A3fooEv( 26define internal i32 @_ZN1A3fooEv(ptr nocapture readnone %this) { 27entry: 28 ret i32 42 29} 30 31; A::bar is not used, so can be deleted with VFE, however, we should not be 32; performing that elimination here. 33; CHECK: define internal i32 @_ZN1A3barEv( 34define internal i32 @_ZN1A3barEv(ptr nocapture readnone %this) { 35entry: 36 ret i32 1337 37} 38 39define dso_local i32 @test_A() { 40entry: 41 %call = tail call ptr @_Znwm(i64 8) 42 store ptr getelementptr inbounds inrange(-16, 16) ({ [4 x ptr] }, ptr @_ZTV1A, i64 0, i32 0, i64 2), ptr %call, align 8 43 %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 44 %1 = extractvalue { ptr, i1 } %0, 0, !nosanitize !9 45 %call1 = tail call i32 %1(ptr nonnull %call) 46 ret i32 %call1 47} 48 49!llvm.module.flags = !{!4} 50 51!0 = !{i64 16, !"_ZTS1A"} 52!1 = !{i64 16, !"_ZTSM1AFivE.virtual"} 53!2 = !{i64 24, !"_ZTSM1AFivE.virtual"} 54!3 = !{i64 2} 55!4 = !{i32 1, !"Virtual Function Elim", i32 0} 56!9 = !{} 57