1; REQUIRES: x86-registered-target 2 3; Test devirtualization requiring promotion of local targets. 4 5; Generate split module with summary for hybrid Thin/Regular LTO WPD. 6; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t1.o %s 7; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t2.o %p/Inputs/devirt2.ll 8 9; Check that we have module flag showing splitting enabled, and that we don't 10; generate summary information needed for index-based WPD. 11; RUN: llvm-modextract -b -n=0 %t2.o -o %t2.o.0 12; RUN: llvm-dis -o - %t2.o.0 | FileCheck %s --check-prefix=ENABLESPLITFLAG --implicit-check-not=vTableFuncs --implicit-check-not=typeidCompatibleVTable 13; RUN: llvm-modextract -b -n=1 %t2.o -o %t2.o.1 14; RUN: llvm-dis -o - %t2.o.1 | FileCheck %s --check-prefix=ENABLESPLITFLAG --implicit-check-not=vTableFuncs --implicit-check-not=typeidCompatibleVTable 15; ENABLESPLITFLAG: !{i32 1, !"EnableSplitLTOUnit", i32 1} 16 17; Generate unsplit module with summary for ThinLTO index-based WPD. 18; Force generation of the bitcode index so that we also test lazy metadata 19; loader handling of the type metadata. 20; RUN: opt -bitcode-mdindex-threshold=0 -thinlto-bc -o %t3.o %s 21; RUN: opt -bitcode-mdindex-threshold=0 -thinlto-bc -o %t4.o %p/Inputs/devirt2.ll 22 23; Check that we don't have module flag when splitting not enabled for ThinLTO, 24; and that we generate summary information needed for index-based WPD. 25; RUN: llvm-dis -o - %t4.o | FileCheck %s --check-prefix=NOENABLESPLITFLAG 26; NOENABLESPLITFLAG-DAG: !{i32 1, !"EnableSplitLTOUnit", i32 0} 27; NOENABLESPLITFLAG-DAG: [[An:\^[0-9]+]] = gv: (name: "_ZN1A1nEi" 28; NOENABLESPLITFLAG-DAG: [[Bf:\^[0-9]+]] = gv: (name: "_ZN1B1fEi" 29; NOENABLESPLITFLAG-DAG: [[Cf:\^[0-9]+]] = gv: (name: "_ZN1C1fEi" 30; NOENABLESPLITFLAG-DAG: [[Dm:\^[0-9]+]] = gv: (name: "_ZN1D1mEi" 31; NOENABLESPLITFLAG-DAG: [[B:\^[0-9]+]] = gv: (name: "_ZTV1B", {{.*}} vTableFuncs: ((virtFunc: [[Bf]], offset: 16), (virtFunc: [[An]], offset: 24)), refs: ([[Bf]], [[An]]) 32; NOENABLESPLITFLAG-DAG: [[C:\^[0-9]+]] = gv: (name: "_ZTV1C", {{.*}} vTableFuncs: ((virtFunc: [[Cf]], offset: 16), (virtFunc: [[An]], offset: 24)), refs: ([[An]], [[Cf]]) 33; NOENABLESPLITFLAG-DAG: [[D:\^[0-9]+]] = gv: (name: "_ZTV1D", {{.*}} vTableFuncs: ((virtFunc: [[Dm]], offset: 16)), refs: ([[Dm]]) 34; NOENABLESPLITFLAG-DAG: typeidCompatibleVTable: (name: "_ZTS1A", summary: ((offset: 16, [[B]]), (offset: 16, [[C]]))) 35; NOENABLESPLITFLAG-DAG: typeidCompatibleVTable: (name: "_ZTS1B", summary: ((offset: 16, [[B]]))) 36; NOENABLESPLITFLAG-DAG: typeidCompatibleVTable: (name: "_ZTS1C", summary: ((offset: 16, [[C]]))) 37; NOENABLESPLITFLAG-DAG: typeidCompatibleVTable: (name: "_ZTS1D", summary: ((offset: 16, [[D]]))) 38 39; Legacy PM, Index based WPD 40; RUN: llvm-lto2 run %t3.o %t4.o -save-temps -pass-remarks=. \ 41; RUN: -whole-program-visibility \ 42; RUN: -wholeprogramdevirt-print-index-based \ 43; RUN: -o %t5 \ 44; RUN: -r=%t3.o,test,px \ 45; RUN: -r=%t3.o,_ZTV1B, \ 46; RUN: -r=%t3.o,_ZTV1C, \ 47; RUN: -r=%t3.o,_ZTV1D, \ 48; RUN: -r=%t3.o,_ZN1D1mEi, \ 49; RUN: -r=%t3.o,test2, \ 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,test2,px \ 54; RUN: -r=%t4.o,_ZTV1B,px \ 55; RUN: -r=%t4.o,_ZTV1C,px \ 56; RUN: -r=%t4.o,_ZTV1D,px \ 57; RUN: -r=%t4.o,_ZTV1E,px 2>&1 | FileCheck %s --check-prefix=REMARK --check-prefix=PRINT 58; RUN: llvm-dis %t5.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR1 59; RUN: llvm-dis %t5.2.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR2 60; RUN: llvm-nm %t5.1 | FileCheck %s --check-prefix=NM-INDEX1 61; RUN: llvm-nm %t5.2 | FileCheck %s --check-prefix=NM-INDEX2 62 63; New PM, Index based WPD 64; RUN: llvm-lto2 run %t3.o %t4.o -save-temps -use-new-pm -pass-remarks=. \ 65; RUN: -whole-program-visibility \ 66; RUN: -wholeprogramdevirt-print-index-based \ 67; RUN: -o %t5 \ 68; RUN: -r=%t3.o,test,px \ 69; RUN: -r=%t3.o,_ZTV1B, \ 70; RUN: -r=%t3.o,_ZTV1C, \ 71; RUN: -r=%t3.o,_ZTV1D, \ 72; RUN: -r=%t3.o,_ZN1D1mEi, \ 73; RUN: -r=%t3.o,test2, \ 74; RUN: -r=%t4.o,_ZN1B1fEi,p \ 75; RUN: -r=%t4.o,_ZN1C1fEi,p \ 76; RUN: -r=%t4.o,_ZN1D1mEi,p \ 77; RUN: -r=%t4.o,test2,px \ 78; RUN: -r=%t4.o,_ZTV1B,px \ 79; RUN: -r=%t4.o,_ZTV1C,px \ 80; RUN: -r=%t4.o,_ZTV1D,px \ 81; RUN: -r=%t4.o,_ZTV1E,px 2>&1 | FileCheck %s --check-prefix=REMARK --check-prefix=PRINT 82; RUN: llvm-dis %t5.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR1 83; RUN: llvm-dis %t5.2.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR2 84; RUN: llvm-nm %t5.1 | FileCheck %s --check-prefix=NM-INDEX1 85; RUN: llvm-nm %t5.2 | FileCheck %s --check-prefix=NM-INDEX2 86 87; NM-INDEX1-DAG: U _ZN1A1nEi.llvm. 88; NM-INDEX1-DAG: U _ZN1E1mEi.llvm. 89; NM-INDEX1-DAG: U _ZN1D1mEi 90 91; NM-INDEX2-DAG: T _ZN1A1nEi.llvm. 92; NM-INDEX2-DAG: T _ZN1E1mEi.llvm. 93; NM-INDEX2-DAG: W _ZN1D1mEi 94; NM-INDEX2-DAG: t _ZN1B1fEi 95; NM-INDEX2-DAG: t _ZN1C1fEi 96 97; Index based WPD, distributed backends 98; RUN: llvm-lto2 run %t3.o %t4.o -save-temps -use-new-pm \ 99; RUN: -whole-program-visibility \ 100; RUN: -thinlto-distributed-indexes -wholeprogramdevirt-print-index-based \ 101; RUN: -o %t5 \ 102; RUN: -r=%t3.o,test,px \ 103; RUN: -r=%t3.o,_ZTV1B, \ 104; RUN: -r=%t3.o,_ZTV1C, \ 105; RUN: -r=%t3.o,_ZTV1D, \ 106; RUN: -r=%t3.o,_ZN1D1mEi, \ 107; RUN: -r=%t3.o,test2, \ 108; RUN: -r=%t4.o,_ZN1B1fEi,p \ 109; RUN: -r=%t4.o,_ZN1C1fEi,p \ 110; RUN: -r=%t4.o,_ZN1D1mEi,p \ 111; RUN: -r=%t4.o,test2,px \ 112; RUN: -r=%t4.o,_ZTV1B,px \ 113; RUN: -r=%t4.o,_ZTV1C,px \ 114; RUN: -r=%t4.o,_ZTV1D,px \ 115; RUN: -r=%t4.o,_ZTV1E,px 2>&1 | FileCheck %s --check-prefix=PRINT 116 117; PRINT-DAG: Devirtualized call to {{.*}} (_ZN1A1nEi) 118; PRINT-DAG: Devirtualized call to {{.*}} (_ZN1E1mEi) 119; PRINT-DAG: Devirtualized call to {{.*}} (_ZN1D1mEi) 120 121; Legacy PM 122; RUN: llvm-lto2 run %t1.o %t2.o -save-temps -pass-remarks=. \ 123; RUN: -whole-program-visibility \ 124; RUN: -o %t5 \ 125; RUN: -r=%t1.o,test,px \ 126; RUN: -r=%t1.o,_ZTV1B, \ 127; RUN: -r=%t1.o,_ZTV1C, \ 128; RUN: -r=%t1.o,_ZTV1D, \ 129; RUN: -r=%t1.o,_ZTV1D, \ 130; RUN: -r=%t1.o,_ZN1D1mEi, \ 131; RUN: -r=%t1.o,_ZN1D1mEi, \ 132; RUN: -r=%t1.o,test2, \ 133; RUN: -r=%t2.o,_ZN1A1nEi,p \ 134; RUN: -r=%t2.o,_ZN1B1fEi,p \ 135; RUN: -r=%t2.o,_ZN1C1fEi,p \ 136; RUN: -r=%t2.o,_ZN1D1mEi,p \ 137; RUN: -r=%t2.o,_ZN1E1mEi,p \ 138; RUN: -r=%t2.o,_ZTV1B, \ 139; RUN: -r=%t2.o,_ZTV1C, \ 140; RUN: -r=%t2.o,_ZTV1D, \ 141; RUN: -r=%t2.o,_ZTV1E, \ 142; RUN: -r=%t2.o,test2,px \ 143; RUN: -r=%t2.o,_ZN1A1nEi, \ 144; RUN: -r=%t2.o,_ZN1B1fEi, \ 145; RUN: -r=%t2.o,_ZN1C1fEi, \ 146; RUN: -r=%t2.o,_ZN1D1mEi, \ 147; RUN: -r=%t2.o,_ZN1E1mEi, \ 148; RUN: -r=%t2.o,_ZTV1B,px \ 149; RUN: -r=%t2.o,_ZTV1C,px \ 150; RUN: -r=%t2.o,_ZTV1D,px \ 151; RUN: -r=%t2.o,_ZTV1E,px 2>&1 | FileCheck %s --check-prefix=REMARK 152; RUN: llvm-dis %t5.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR1 153; RUN: llvm-dis %t5.2.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR2 154; RUN: llvm-nm %t5.1 | FileCheck %s --check-prefix=NM-HYBRID1 155; RUN: llvm-nm %t5.2 | FileCheck %s --check-prefix=NM-HYBRID2 156 157; New PM 158; RUN: llvm-lto2 run %t1.o %t2.o -save-temps -use-new-pm -pass-remarks=. \ 159; RUN: -whole-program-visibility \ 160; RUN: -o %t5 \ 161; RUN: -r=%t1.o,test,px \ 162; RUN: -r=%t1.o,_ZTV1B, \ 163; RUN: -r=%t1.o,_ZTV1C, \ 164; RUN: -r=%t1.o,_ZTV1D, \ 165; RUN: -r=%t1.o,_ZTV1D, \ 166; RUN: -r=%t1.o,_ZN1D1mEi, \ 167; RUN: -r=%t1.o,_ZN1D1mEi, \ 168; RUN: -r=%t1.o,test2, \ 169; RUN: -r=%t2.o,_ZN1A1nEi,p \ 170; RUN: -r=%t2.o,_ZN1B1fEi,p \ 171; RUN: -r=%t2.o,_ZN1C1fEi,p \ 172; RUN: -r=%t2.o,_ZN1D1mEi,p \ 173; RUN: -r=%t2.o,_ZN1E1mEi,p \ 174; RUN: -r=%t2.o,_ZTV1B, \ 175; RUN: -r=%t2.o,_ZTV1C, \ 176; RUN: -r=%t2.o,_ZTV1D, \ 177; RUN: -r=%t2.o,_ZTV1E, \ 178; RUN: -r=%t2.o,test2,px \ 179; RUN: -r=%t2.o,_ZN1A1nEi, \ 180; RUN: -r=%t2.o,_ZN1B1fEi, \ 181; RUN: -r=%t2.o,_ZN1C1fEi, \ 182; RUN: -r=%t2.o,_ZN1D1mEi, \ 183; RUN: -r=%t2.o,_ZN1E1mEi, \ 184; RUN: -r=%t2.o,_ZTV1B,px \ 185; RUN: -r=%t2.o,_ZTV1C,px \ 186; RUN: -r=%t2.o,_ZTV1D,px \ 187; RUN: -r=%t2.o,_ZTV1E,px 2>&1 | FileCheck %s --check-prefix=REMARK 188; RUN: llvm-dis %t5.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR1 189; RUN: llvm-dis %t5.2.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR2 190; RUN: llvm-nm %t5.1 | FileCheck %s --check-prefix=NM-HYBRID1 191; RUN: llvm-nm %t5.2 | FileCheck %s --check-prefix=NM-HYBRID2 192 193; NM-HYBRID1-DAG: U _ZN1A1nEi$ 194; NM-HYBRID1-DAG: U _ZN1E1mEi$ 195; NM-HYBRID1-DAG: U _ZN1D1mEi 196 197; NM-HYBRID2-DAG: T _ZN1A1nEi$ 198; NM-HYBRID2-DAG: T _ZN1E1mEi$ 199; NM-HYBRID2-DAG: W _ZN1D1mEi 200; NM-HYBRID2-DAG: T _ZN1B1fEi 201; NM-HYBRID2-DAG: T _ZN1C1fEi 202 203; REMARK-DAG: single-impl: devirtualized a call to _ZN1A1nEi 204; REMARK-DAG: single-impl: devirtualized a call to _ZN1D1mEi 205; We should devirt call to _ZN1E1mEi once in importing module and once 206; in original (exporting) module. 207; REMARK-DAG: single-impl: devirtualized a call to _ZN1E1mEi 208; REMARK-DAG: single-impl: devirtualized a call to _ZN1E1mEi 209 210target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 211target triple = "x86_64-grtev4-linux-gnu" 212 213%struct.A = type { i32 (...)** } 214%struct.B = type { %struct.A } 215%struct.C = type { %struct.A } 216%struct.D = type { i32 (...)** } 217%struct.E = type { i32 (...)** } 218 219@_ZTV1B = external constant [4 x i8*] 220@_ZTV1C = external constant [4 x i8*] 221;@_ZTV1D = external constant [3 x i8*] 222@_ZTV1D = linkonce_odr constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* undef, i8* bitcast (i32 (%struct.D*, i32)* @_ZN1D1mEi to i8*)] }, !type !3 223 224define linkonce_odr i32 @_ZN1D1mEi(%struct.D* %this, i32 %a) #0 { 225 ret i32 0 226} 227 228; CHECK-IR1-LABEL: define i32 @test 229define i32 @test(%struct.A* %obj, %struct.D* %obj2, %struct.E* %obj3, i32 %a) { 230entry: 231 %0 = bitcast %struct.A* %obj to i8*** 232 %vtable = load i8**, i8*** %0 233 %1 = bitcast i8** %vtable to i8* 234 %p = call i1 @llvm.type.test(i8* %1, metadata !"_ZTS1A") 235 call void @llvm.assume(i1 %p) 236 %fptrptr = getelementptr i8*, i8** %vtable, i32 1 237 %2 = bitcast i8** %fptrptr to i32 (%struct.A*, i32)** 238 %fptr1 = load i32 (%struct.A*, i32)*, i32 (%struct.A*, i32)** %2, align 8 239 240 ; Check that the call was devirtualized. Ignore extra character before 241 ; symbol name which would happen if it was promoted during module 242 ; splitting for hybrid WPD. 243 ; CHECK-IR1: %call = tail call i32 bitcast (void ()* @{{.*}}_ZN1A1nEi 244 %call = tail call i32 %fptr1(%struct.A* nonnull %obj, i32 %a) 245 246 %3 = bitcast i8** %vtable to i32 (%struct.A*, i32)** 247 %fptr22 = load i32 (%struct.A*, i32)*, i32 (%struct.A*, i32)** %3, align 8 248 249 ; We still have to call it as virtual. 250 ; CHECK-IR1: %call3 = tail call i32 %fptr22 251 %call3 = tail call i32 %fptr22(%struct.A* nonnull %obj, i32 %call) 252 253 %4 = bitcast %struct.D* %obj2 to i8*** 254 %vtable2 = load i8**, i8*** %4 255 %5 = bitcast i8** %vtable2 to i8* 256 %p2 = call i1 @llvm.type.test(i8* %5, metadata !"_ZTS1D") 257 call void @llvm.assume(i1 %p2) 258 259 %6 = bitcast i8** %vtable2 to i32 (%struct.D*, i32)** 260 %fptr33 = load i32 (%struct.D*, i32)*, i32 (%struct.D*, i32)** %6, align 8 261 262 ; Check that the call was devirtualized. 263 ; CHECK-IR1: %call4 = tail call i32 @_ZN1D1mEi 264 %call4 = tail call i32 %fptr33(%struct.D* nonnull %obj2, i32 %call3) 265 266 %call5 = tail call i32 @test2(%struct.E* nonnull %obj3, i32 %call4) 267 ret i32 %call5 268} 269; CHECK-IR1-LABEL: ret i32 270; CHECK-IR1-LABEL: } 271 272; CHECK-IR2: define i32 @test2 273; CHECK-IR2-NEXT: entry: 274; Check that the call was devirtualized. Ignore extra character before 275; symbol name which would happen if it was promoted during module 276; splitting for hybrid WPD. 277; CHECK-IR2-NEXT: %call4 = tail call i32 @{{.*}}_ZN1E1mEi 278 279declare i1 @llvm.type.test(i8*, metadata) 280declare void @llvm.assume(i1) 281declare i32 @test2(%struct.E* %obj, i32 %a) 282 283attributes #0 = { noinline optnone } 284 285!3 = !{i64 16, !"_ZTS1D"} 286