159 lines · plain
1; RUN: rm -rf %t && mkdir %t && cd %t2 3; Tests that devirtualization is suppressed on a class when the LTO unit doesn't4; have the prevailing definition of the base class.5 6; Generate unsplit module with summary for ThinLTO index-based WPD.7; RUN: opt -thinlto-bc -o summary.o %s8 9; Index based WPD10; The callsite inside @_ZN4Base8dispatchEv gets devirtualized when symbol11; resolution shows there is a prevailing definition of `_ZTI7Derived` in the12; LTO unit.13; RUN: llvm-lto2 run summary.o -save-temps -pass-remarks=. \14; RUN: -thinlto-threads=1 \15; RUN: -o tmp \16; RUN: --whole-program-visibility-enabled-in-lto=true \17; RUN: --validate-all-vtables-have-type-infos=true \18; RUN: --all-vtables-have-type-infos=true \19; RUN: -r=summary.o,_ZN4Base8dispatchEv,px \20; RUN: -r=summary.o,_ZN8DerivedN5printEv,px \21; RUN: -r=summary.o,_ZTV8DerivedN,p \22; RUN: -r=summary.o,_ZTI8DerivedN,p \23; RUN: -r=summary.o,_ZTS8DerivedN,p \24; RUN: -r=summary.o,_ZTI7Derived,p \25; RUN: 2>&1 | FileCheck --allow-empty %s --check-prefix=REMARK26 27 28; Index based WPD29; The callsite inside @_ZN4Base8dispatchEv remains indirect and not de-virtualized30; when symbol resolution shows there isn't a prevailing definition of31; `_ZTI7Derived` in the LTO unit.32; RUN: llvm-lto2 run summary.o -save-temps -pass-remarks=. \33; RUN: -thinlto-threads=1 \34; RUN: -o tmp \35; RUN: --whole-program-visibility-enabled-in-lto=true \36; RUN: --validate-all-vtables-have-type-infos=true \37; RUN: --all-vtables-have-type-infos=true \38; RUN: -r=summary.o,_ZN4Base8dispatchEv,px \39; RUN: -r=summary.o,_ZN8DerivedN5printEv,px \40; RUN: -r=summary.o,_ZTV8DerivedN,p \41; RUN: -r=summary.o,_ZTI8DerivedN,p \42; RUN: -r=summary.o,_ZTS8DerivedN,p \43; RUN: -r=summary.o,_ZTI7Derived, \44; RUN: 2>&1 | FileCheck %s --allow-empty --implicit-check-not='single-impl: devirtualized a call to'45 46; Repeat the above tests for WPD in hybrid LTO.47; RUN: opt --thinlto-bc --thinlto-split-lto-unit -o hybrid.o %s48 49; RUN: llvm-lto2 run hybrid.o -save-temps -pass-remarks=. \50; RUN: -thinlto-threads=1 \51; RUN: -o hybrid-tmp \52; RUN: --whole-program-visibility-enabled-in-lto=true \53; RUN: --validate-all-vtables-have-type-infos=true \54; RUN: --all-vtables-have-type-infos=true \55; RUN: -r=hybrid.o,_ZN4Base8dispatchEv,px \56; RUN: -r=hybrid.o,_ZN8DerivedN5printEv,px \57; RUN: -r=hybrid.o,_ZTV8DerivedN, \58; RUN: -r=hybrid.o,_ZTI8DerivedN, \59; RUN: -r=hybrid.o,_ZTS8DerivedN,p \60; RUN: -r=hybrid.o,_ZTI7Derived,p \61; RUN: -r=hybrid.o,_ZN8DerivedN5printEv, \62; RUN: -r=hybrid.o,_ZTV8DerivedN,p \63; RUN: -r=hybrid.o,_ZTI8DerivedN,p \64; RUN: 2>&1 | FileCheck --allow-empty %s --check-prefix=REMARK65 66 67; RUN: llvm-lto2 run hybrid.o -save-temps -pass-remarks=. \68; RUN: -thinlto-threads=1 \69; RUN: -o hybrid-tmp \70; RUN: --whole-program-visibility-enabled-in-lto=true \71; RUN: --validate-all-vtables-have-type-infos=true \72; RUN: --all-vtables-have-type-infos=true \73; RUN: -r=hybrid.o,_ZN4Base8dispatchEv,px \74; RUN: -r=hybrid.o,_ZN8DerivedN5printEv,px \75; RUN: -r=hybrid.o,_ZTV8DerivedN, \76; RUN: -r=hybrid.o,_ZTI8DerivedN, \77; RUN: -r=hybrid.o,_ZTS8DerivedN,p \78; RUN: -r=hybrid.o,_ZTI7Derived, \79; RUN: -r=hybrid.o,_ZN8DerivedN5printEv, \80; RUN: -r=hybrid.o,_ZTV8DerivedN,p \81; RUN: -r=hybrid.o,_ZTI8DerivedN,p \82; RUN: 2>&1 | FileCheck --allow-empty %s --implicit-check-not='single-impl: devirtualized a call to'83 84 85; Repeat the above tests for WPD in regular LTO.86; RUN: opt -module-summary -o regular.o %s87 88; RUN: llvm-lto2 run regular.o -save-temps -pass-remarks=. \89; RUN: -thinlto-threads=1 \90; RUN: -o regular-temp \91; RUN: --whole-program-visibility-enabled-in-lto=true \92; RUN: --validate-all-vtables-have-type-infos=true \93; RUN: --all-vtables-have-type-infos=true \94; RUN: -r=regular.o,_ZN4Base8dispatchEv,px \95; RUN: -r=regular.o,_ZN8DerivedN5printEv,px \96; RUN: -r=regular.o,_ZTS8DerivedN,p \97; RUN: -r=regular.o,_ZTI7Derived,p \98; RUN: -r=regular.o,_ZTV8DerivedN,p \99; RUN: -r=regular.o,_ZTI8DerivedN,p \100; RUN: 2>&1 | FileCheck --allow-empty %s --check-prefix=REMARK101 102; RUN: llvm-lto2 run regular.o -save-temps -pass-remarks=. \103; RUN: -thinlto-threads=1 \104; RUN: -o regular-temp \105; RUN: --whole-program-visibility-enabled-in-lto=true \106; RUN: --validate-all-vtables-have-type-infos=true \107; RUN: --all-vtables-have-type-infos=true \108; RUN: -r=regular.o,_ZN4Base8dispatchEv,px \109; RUN: -r=regular.o,_ZN8DerivedN5printEv,px \110; RUN: -r=regular.o,_ZTS8DerivedN,p \111; RUN: -r=regular.o,_ZTI7Derived, \112; RUN: -r=regular.o,_ZTV8DerivedN,p \113; RUN: -r=regular.o,_ZTI8DerivedN,p \114; RUN: 2>&1 | FileCheck --allow-empty %s --implicit-check-not='single-impl: devirtualized a call to'115 116; REMARK: single-impl: devirtualized a call to _ZN8DerivedN5printEv117 118target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"119target triple = "x86_64-unknown-linux-gnu"120 121@_ZTV8DerivedN = linkonce_odr hidden constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr @_ZTI8DerivedN, ptr @_ZN8DerivedN5printEv] }, !type !0, !type !1, !type !2, !type !3, !vcall_visibility !4122@_ZTI8DerivedN = linkonce_odr hidden constant { ptr, ptr, ptr } { ptr null, ptr @_ZTS8DerivedN, ptr @_ZTI7Derived }123@_ZTS8DerivedN = linkonce_odr hidden constant [10 x i8] c"8DerivedN\00", align 1124@_ZTI7Derived = external constant ptr125 126; Whole program devirtualization will ignore summaries that are not live.127; Mark '_ZTV8DerivedN' as used so it remains live.128@llvm.used = appending global [1 x ptr] [ptr @_ZTV8DerivedN], section "llvm.metadata"129 130define hidden void @_ZN4Base8dispatchEv(ptr %this) {131entry:132 %this.addr = alloca ptr133 store ptr %this, ptr %this.addr134 %this1 = load ptr, ptr %this.addr135 %vtable = load ptr, ptr %this1136 %0 = call i1 @llvm.type.test(ptr %vtable, metadata !"_ZTS7Derived")137 call void @llvm.assume(i1 %0)138 %vfn = getelementptr inbounds ptr, ptr %vtable, i64 0139 %1 = load ptr, ptr %vfn140 call void %1(ptr %this1)141 ret void142}143 144define linkonce_odr hidden void @_ZN8DerivedN5printEv(ptr %this) #0 {145entry:146 ret void147}148 149attributes #0 = { noinline optnone }150 151declare i1 @llvm.type.test(ptr, metadata)152declare void @llvm.assume(i1)153 154!0 = !{i64 16, !"_ZTS7Derived"}155!1 = !{i64 16, !"_ZTSM7DerivedFvvE.virtual"}156!2 = !{i64 16, !"_ZTS8DerivedN"}157!3 = !{i64 16, !"_ZTSM8DerivedNFvvE.virtual"}158!4 = !{i64 0}159