135 lines · plain
1; REQUIRES: x86-registered-target2 3; Test devirtualization through the thin link and backend, when vtables4; have vcall_visibility metadata with public visibility.5 6; Index based WPD7; Generate unsplit module with summary for ThinLTO index-based WPD.8; RUN: opt -thinlto-bc -o %t2.o %s9; RUN: llvm-lto2 run %t2.o -save-temps -pass-remarks=. \10; RUN: -o %t3 \11; RUN: -r=%t2.o,test,px \12; RUN: -r=%t2.o,_ZN1A1nEi,p \13; RUN: -r=%t2.o,_ZN1B1fEi,p \14; RUN: -r=%t2.o,_ZN1C1fEi,p \15; RUN: -r=%t2.o,_ZN1D1mEi,p \16; RUN: -r=%t2.o,_ZTV1B,px \17; RUN: -r=%t2.o,_ZTV1C,px \18; RUN: -r=%t2.o,_ZTV1D,px 2>&1 | FileCheck %s --check-prefix=REMARK19; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR20 21; Hybrid WPD22; Generate split module with summary for hybrid Thin/Regular LTO WPD.23; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t.o %s24; RUN: llvm-lto2 run %t.o -save-temps -pass-remarks=. \25; RUN: -o %t3 \26; RUN: -r=%t.o,test,px \27; RUN: -r=%t.o,_ZN1A1nEi,p \28; RUN: -r=%t.o,_ZN1B1fEi,p \29; RUN: -r=%t.o,_ZN1C1fEi,p \30; RUN: -r=%t.o,_ZN1D1mEi,p \31; RUN: -r=%t.o,_ZTV1B, \32; RUN: -r=%t.o,_ZTV1C, \33; RUN: -r=%t.o,_ZTV1D, \34; RUN: -r=%t.o,_ZN1A1nEi, \35; RUN: -r=%t.o,_ZN1B1fEi, \36; RUN: -r=%t.o,_ZN1C1fEi, \37; RUN: -r=%t.o,_ZN1D1mEi, \38; RUN: -r=%t.o,_ZTV1B,px \39; RUN: -r=%t.o,_ZTV1C,px \40; RUN: -r=%t.o,_ZTV1D,px 2>&1 | FileCheck %s --check-prefix=REMARK --dump-input=fail41; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR42 43; Regular LTO WPD44; RUN: opt -o %t4.o %s45; RUN: llvm-lto2 run %t4.o -save-temps -pass-remarks=. \46; RUN: -whole-program-visibility \47; RUN: -o %t5 \48; RUN: -r=%t4.o,test,px \49; RUN: -r=%t4.o,_ZN1A1nEi,p \50; RUN: -r=%t4.o,_ZN1B1fEi,p \51; RUN: -r=%t4.o,_ZN1C1fEi,p \52; RUN: -r=%t4.o,_ZN1D1mEi,p \53; RUN: -r=%t4.o,_ZTV1B,px \54; RUN: -r=%t4.o,_ZTV1C,px \55; RUN: -r=%t4.o,_ZTV1D,px 2>&1 | FileCheck %s --check-prefix=REMARK56; RUN: llvm-dis %t5.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR57 58; REMARK-DAG: single-impl: devirtualized a call to _ZN1A1nEi59; REMARK-DAG: single-impl: devirtualized a call to _ZN1D1mEi60 61target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"62target triple = "x86_64-grtev4-linux-gnu"63 64%struct.A = type { ptr }65%struct.B = type { %struct.A }66%struct.C = type { %struct.A }67%struct.D = type { ptr }68 69@_ZTV1B = constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr undef, ptr @_ZN1B1fEi, ptr @_ZN1A1nEi] }, !type !0, !type !1, !vcall_visibility !570@_ZTV1C = constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr undef, ptr @_ZN1C1fEi, ptr @_ZN1A1nEi] }, !type !0, !type !2, !vcall_visibility !571@_ZTV1D = constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr undef, ptr @_ZN1D1mEi] }, !type !3, !vcall_visibility !572 73 74; CHECK-IR-LABEL: define {{(noundef )?}}i32 @test75define i32 @test(ptr %obj, ptr %obj2, i32 %a) {76entry:77 %vtable = load ptr, ptr %obj78 %p = call i1 @llvm.type.test(ptr %vtable, metadata !"_ZTS1A")79 call void @llvm.assume(i1 %p)80 %fptrptr = getelementptr ptr, ptr %vtable, i32 181 %fptr1 = load ptr, ptr %fptrptr, align 882 83 ; Check that the call was devirtualized.84 ; CHECK-IR: %call = tail call i32 @_ZN1A1nEi85 %call = tail call i32 %fptr1(ptr nonnull %obj, i32 %a)86 87 %fptr22 = load ptr, ptr %vtable, align 888 89 ; We still have to call it as virtual.90 ; CHECK-IR: %call3 = tail call i32 %fptr2291 %call3 = tail call i32 %fptr22(ptr nonnull %obj, i32 %call)92 93 %vtable2 = load ptr, ptr %obj294 %p2 = call i1 @llvm.type.test(ptr %vtable2, metadata !4)95 call void @llvm.assume(i1 %p2)96 97 %fptr33 = load ptr, ptr %vtable2, align 898 99 ; Check that the call was devirtualized.100 ; CHECK-IR: %call4 = tail call i32 @_ZN1D1mEi101 %call4 = tail call i32 %fptr33(ptr nonnull %obj2, i32 %call3)102 ret i32 %call4103}104; CHECK-IR-LABEL: ret i32105; CHECK-IR-LABEL: }106 107declare i1 @llvm.type.test(ptr, metadata)108declare void @llvm.assume(i1)109 110define i32 @_ZN1B1fEi(ptr %this, i32 %a) #0 {111 ret i32 0;112}113 114define i32 @_ZN1A1nEi(ptr %this, i32 %a) #0 {115 ret i32 0;116}117 118define i32 @_ZN1C1fEi(ptr %this, i32 %a) #0 {119 ret i32 0;120}121 122define i32 @_ZN1D1mEi(ptr %this, i32 %a) #0 {123 ret i32 0;124}125 126; Make sure we don't inline or otherwise optimize out the direct calls.127attributes #0 = { noinline optnone }128 129!0 = !{i64 16, !"_ZTS1A"}130!1 = !{i64 16, !"_ZTS1B"}131!2 = !{i64 16, !"_ZTS1C"}132!3 = !{i64 16, !4}133!4 = distinct !{}134!5 = !{i64 1}135