1; REQUIRES: x86-registered-target 2 3; Test devirtualization through the thin link and backend, when vtables 4; have vcall_visibility metadata with public visibility. 5 6; Index based WPD 7; Generate unsplit module with summary for ThinLTO index-based WPD. 8; RUN: opt -thinlto-bc -o %t2.o %s 9; RUN: llvm-lto2 run %t2.o -save-temps -use-new-pm -pass-remarks=. \ 10; RUN: -whole-program-visibility \ 11; RUN: -o %t3 \ 12; RUN: -r=%t2.o,test,px \ 13; RUN: -r=%t2.o,_ZN1A1nEi,p \ 14; RUN: -r=%t2.o,_ZN1B1fEi,p \ 15; RUN: -r=%t2.o,_ZN1C1fEi,p \ 16; RUN: -r=%t2.o,_ZN1D1mEi,p \ 17; RUN: -r=%t2.o,_ZTV1B,px \ 18; RUN: -r=%t2.o,_ZTV1C,px \ 19; RUN: -r=%t2.o,_ZTV1D,px 2>&1 | FileCheck %s --check-prefix=REMARK 20; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR 21 22; Hybrid WPD 23; Generate split module with summary for hybrid Thin/Regular LTO WPD. 24; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t.o %s 25; FIXME: Fix machine verifier issues and remove -verify-machineinstrs=0. PR39436. 26; RUN: llvm-lto2 run %t.o -save-temps -use-new-pm -pass-remarks=. \ 27; RUN: -whole-program-visibility \ 28; RUN: -verify-machineinstrs=0 \ 29; RUN: -o %t3 \ 30; RUN: -r=%t.o,test,px \ 31; RUN: -r=%t.o,_ZN1A1nEi,p \ 32; RUN: -r=%t.o,_ZN1B1fEi,p \ 33; RUN: -r=%t.o,_ZN1C1fEi,p \ 34; RUN: -r=%t.o,_ZN1D1mEi,p \ 35; RUN: -r=%t.o,_ZTV1B, \ 36; RUN: -r=%t.o,_ZTV1C, \ 37; RUN: -r=%t.o,_ZTV1D, \ 38; RUN: -r=%t.o,_ZN1A1nEi, \ 39; RUN: -r=%t.o,_ZN1B1fEi, \ 40; RUN: -r=%t.o,_ZN1C1fEi, \ 41; RUN: -r=%t.o,_ZN1D1mEi, \ 42; RUN: -r=%t.o,_ZTV1B,px \ 43; RUN: -r=%t.o,_ZTV1C,px \ 44; RUN: -r=%t.o,_ZTV1D,px 2>&1 | FileCheck %s --check-prefix=REMARK --dump-input=fail 45; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR 46 47; Regular LTO WPD 48; RUN: opt -o %t4.o %s 49; RUN: llvm-lto2 run %t4.o -save-temps -use-new-pm -pass-remarks=. \ 50; RUN: -whole-program-visibility \ 51; RUN: -o %t5 \ 52; RUN: -r=%t4.o,test,px \ 53; RUN: -r=%t4.o,_ZN1A1nEi,p \ 54; RUN: -r=%t4.o,_ZN1B1fEi,p \ 55; RUN: -r=%t4.o,_ZN1C1fEi,p \ 56; RUN: -r=%t4.o,_ZN1D1mEi,p \ 57; RUN: -r=%t4.o,_ZTV1B,px \ 58; RUN: -r=%t4.o,_ZTV1C,px \ 59; RUN: -r=%t4.o,_ZTV1D,px 2>&1 | FileCheck %s --check-prefix=REMARK 60; RUN: llvm-dis %t5.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR 61 62; REMARK-DAG: single-impl: devirtualized a call to _ZN1A1nEi 63; REMARK-DAG: single-impl: devirtualized a call to _ZN1D1mEi 64 65; Try everything again but without -whole-program-visibility to confirm 66; WPD fails 67 68; Index based WPD 69; RUN: llvm-lto2 run %t2.o -save-temps -use-new-pm -pass-remarks=. \ 70; RUN: -o %t3 \ 71; RUN: -r=%t2.o,test,px \ 72; RUN: -r=%t2.o,_ZN1A1nEi,p \ 73; RUN: -r=%t2.o,_ZN1B1fEi,p \ 74; RUN: -r=%t2.o,_ZN1C1fEi,p \ 75; RUN: -r=%t2.o,_ZN1D1mEi,p \ 76; RUN: -r=%t2.o,_ZTV1B,px \ 77; RUN: -r=%t2.o,_ZTV1C,px \ 78; RUN: -r=%t2.o,_ZTV1D,px 2>&1 | FileCheck %s --implicit-check-not single-impl --allow-empty 79; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-NODEVIRT-IR 80 81; Hybrid WPD 82; RUN: llvm-lto2 run %t.o -save-temps -use-new-pm -pass-remarks=. \ 83; RUN: -verify-machineinstrs=0 \ 84; RUN: -o %t3 \ 85; RUN: -r=%t.o,test,px \ 86; RUN: -r=%t.o,_ZN1A1nEi,p \ 87; RUN: -r=%t.o,_ZN1B1fEi,p \ 88; RUN: -r=%t.o,_ZN1C1fEi,p \ 89; RUN: -r=%t.o,_ZN1D1mEi,p \ 90; RUN: -r=%t.o,_ZTV1B, \ 91; RUN: -r=%t.o,_ZTV1C, \ 92; RUN: -r=%t.o,_ZTV1D, \ 93; RUN: -r=%t.o,_ZN1A1nEi, \ 94; RUN: -r=%t.o,_ZN1B1fEi, \ 95; RUN: -r=%t.o,_ZN1C1fEi, \ 96; RUN: -r=%t.o,_ZN1D1mEi, \ 97; RUN: -r=%t.o,_ZTV1B,px \ 98; RUN: -r=%t.o,_ZTV1C,px \ 99; RUN: -r=%t.o,_ZTV1D,px 2>&1 | FileCheck %s --implicit-check-not single-impl --allow-empty 100; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-NODEVIRT-IR 101 102; Regular LTO WPD 103; RUN: llvm-lto2 run %t4.o -save-temps -use-new-pm -pass-remarks=. \ 104; RUN: -o %t5 \ 105; RUN: -r=%t4.o,test,px \ 106; RUN: -r=%t4.o,_ZN1A1nEi,p \ 107; RUN: -r=%t4.o,_ZN1B1fEi,p \ 108; RUN: -r=%t4.o,_ZN1C1fEi,p \ 109; RUN: -r=%t4.o,_ZN1D1mEi,p \ 110; RUN: -r=%t4.o,_ZTV1B,px \ 111; RUN: -r=%t4.o,_ZTV1C,px \ 112; RUN: -r=%t4.o,_ZTV1D,px 2>&1 | FileCheck %s --implicit-check-not single-impl --allow-empty 113; RUN: llvm-dis %t5.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-NODEVIRT-IR 114 115; Try index-based WPD again with both -whole-program-visibility and 116; -disable-whole-program-visibility to confirm the latter overrides 117; the former and that WPD fails. 118; RUN: llvm-lto2 run %t2.o -save-temps -use-new-pm -pass-remarks=. \ 119; RUN: -whole-program-visibility \ 120; RUN: -disable-whole-program-visibility \ 121; RUN: -o %t3 \ 122; RUN: -r=%t2.o,test,px \ 123; RUN: -r=%t2.o,_ZN1A1nEi,p \ 124; RUN: -r=%t2.o,_ZN1B1fEi,p \ 125; RUN: -r=%t2.o,_ZN1C1fEi,p \ 126; RUN: -r=%t2.o,_ZN1D1mEi,p \ 127; RUN: -r=%t2.o,_ZTV1B,px \ 128; RUN: -r=%t2.o,_ZTV1C,px \ 129; RUN: -r=%t2.o,_ZTV1D,px 2>&1 | FileCheck %s --implicit-check-not single-impl --allow-empty 130; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-NODEVIRT-IR 131 132target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 133target triple = "x86_64-grtev4-linux-gnu" 134 135%struct.A = type { i32 (...)** } 136%struct.B = type { %struct.A } 137%struct.C = type { %struct.A } 138%struct.D = type { i32 (...)** } 139 140@_ZTV1B = constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* undef, i8* bitcast (i32 (%struct.B*, i32)* @_ZN1B1fEi to i8*), i8* bitcast (i32 (%struct.A*, i32)* @_ZN1A1nEi to i8*)] }, !type !0, !type !1, !vcall_visibility !5 141@_ZTV1C = constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* undef, i8* bitcast (i32 (%struct.C*, i32)* @_ZN1C1fEi to i8*), i8* bitcast (i32 (%struct.A*, i32)* @_ZN1A1nEi to i8*)] }, !type !0, !type !2, !vcall_visibility !5 142@_ZTV1D = constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* undef, i8* bitcast (i32 (%struct.D*, i32)* @_ZN1D1mEi to i8*)] }, !type !3, !vcall_visibility !5 143 144 145; CHECK-IR-LABEL: define i32 @test 146define i32 @test(%struct.A* %obj, %struct.D* %obj2, i32 %a) { 147entry: 148 %0 = bitcast %struct.A* %obj to i8*** 149 %vtable = load i8**, i8*** %0 150 %1 = bitcast i8** %vtable to i8* 151 %p = call i1 @llvm.type.test(i8* %1, metadata !"_ZTS1A") 152 call void @llvm.assume(i1 %p) 153 %fptrptr = getelementptr i8*, i8** %vtable, i32 1 154 %2 = bitcast i8** %fptrptr to i32 (%struct.A*, i32)** 155 %fptr1 = load i32 (%struct.A*, i32)*, i32 (%struct.A*, i32)** %2, align 8 156 157 ; Check that the call was devirtualized. 158 ; CHECK-IR: %call = tail call i32 @_ZN1A1nEi 159 ; CHECK-NODEVIRT-IR: %call = tail call i32 %fptr1 160 %call = tail call i32 %fptr1(%struct.A* nonnull %obj, i32 %a) 161 162 %3 = bitcast i8** %vtable to i32 (%struct.A*, i32)** 163 %fptr22 = load i32 (%struct.A*, i32)*, i32 (%struct.A*, i32)** %3, align 8 164 165 ; We still have to call it as virtual. 166 ; CHECK-IR: %call3 = tail call i32 %fptr22 167 ; CHECK-NODEVIRT-IR: %call3 = tail call i32 %fptr22 168 %call3 = tail call i32 %fptr22(%struct.A* nonnull %obj, i32 %call) 169 170 %4 = bitcast %struct.D* %obj2 to i8*** 171 %vtable2 = load i8**, i8*** %4 172 %5 = bitcast i8** %vtable2 to i8* 173 %p2 = call i1 @llvm.type.test(i8* %5, metadata !4) 174 call void @llvm.assume(i1 %p2) 175 176 %6 = bitcast i8** %vtable2 to i32 (%struct.D*, i32)** 177 %fptr33 = load i32 (%struct.D*, i32)*, i32 (%struct.D*, i32)** %6, align 8 178 179 ; Check that the call was devirtualized. 180 ; CHECK-IR: %call4 = tail call i32 @_ZN1D1mEi 181 ; CHECK-NODEVIRT-IR: %call4 = tail call i32 %fptr33 182 %call4 = tail call i32 %fptr33(%struct.D* nonnull %obj2, i32 %call3) 183 ret i32 %call4 184} 185; CHECK-IR-LABEL: ret i32 186; CHECK-IR-LABEL: } 187 188declare i1 @llvm.type.test(i8*, metadata) 189declare void @llvm.assume(i1) 190 191define i32 @_ZN1B1fEi(%struct.B* %this, i32 %a) #0 { 192 ret i32 0; 193} 194 195define i32 @_ZN1A1nEi(%struct.A* %this, i32 %a) #0 { 196 ret i32 0; 197} 198 199define i32 @_ZN1C1fEi(%struct.C* %this, i32 %a) #0 { 200 ret i32 0; 201} 202 203define i32 @_ZN1D1mEi(%struct.D* %this, i32 %a) #0 { 204 ret i32 0; 205} 206 207; Make sure we don't inline or otherwise optimize out the direct calls. 208attributes #0 = { noinline optnone } 209 210!0 = !{i64 16, !"_ZTS1A"} 211!1 = !{i64 16, !"_ZTS1B"} 212!2 = !{i64 16, !"_ZTS1C"} 213!3 = !{i64 16, !4} 214!4 = distinct !{} 215!5 = !{i64 0} 216