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; 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; NM-INDEX1-DAG: U _ZN1A1nEi.llvm. 64; NM-INDEX1-DAG: U _ZN1E1mEi.llvm. 65; NM-INDEX1-DAG: U _ZN1D1mEi 66 67; NM-INDEX2-DAG: T _ZN1A1nEi.llvm. 68; NM-INDEX2-DAG: T _ZN1E1mEi.llvm. 69; NM-INDEX2-DAG: W _ZN1D1mEi 70; NM-INDEX2-DAG: t _ZN1B1fEi 71; NM-INDEX2-DAG: t _ZN1C1fEi 72 73; Index based WPD, distributed backends 74; RUN: llvm-lto2 run %t3.o %t4.o -save-temps \ 75; RUN: -whole-program-visibility \ 76; RUN: -thinlto-distributed-indexes -wholeprogramdevirt-print-index-based \ 77; RUN: -o %t5 \ 78; RUN: -r=%t3.o,test,px \ 79; RUN: -r=%t3.o,_ZTV1B, \ 80; RUN: -r=%t3.o,_ZTV1C, \ 81; RUN: -r=%t3.o,_ZTV1D, \ 82; RUN: -r=%t3.o,_ZN1D1mEi, \ 83; RUN: -r=%t3.o,test2, \ 84; RUN: -r=%t4.o,_ZN1B1fEi,p \ 85; RUN: -r=%t4.o,_ZN1C1fEi,p \ 86; RUN: -r=%t4.o,_ZN1D1mEi,p \ 87; RUN: -r=%t4.o,test2,px \ 88; RUN: -r=%t4.o,_ZTV1B,px \ 89; RUN: -r=%t4.o,_ZTV1C,px \ 90; RUN: -r=%t4.o,_ZTV1D,px \ 91; RUN: -r=%t4.o,_ZTV1E,px 2>&1 | FileCheck %s --check-prefix=PRINT 92 93; PRINT-DAG: Devirtualized call to {{.*}} (_ZN1A1nEi) 94; PRINT-DAG: Devirtualized call to {{.*}} (_ZN1E1mEi) 95; PRINT-DAG: Devirtualized call to {{.*}} (_ZN1D1mEi) 96 97; New PM 98; RUN: llvm-lto2 run %t1.o %t2.o -save-temps -pass-remarks=. \ 99; RUN: -whole-program-visibility \ 100; RUN: -o %t5 \ 101; RUN: -r=%t1.o,test,px \ 102; RUN: -r=%t1.o,_ZTV1B, \ 103; RUN: -r=%t1.o,_ZTV1C, \ 104; RUN: -r=%t1.o,_ZTV1D, \ 105; RUN: -r=%t1.o,_ZTV1D, \ 106; RUN: -r=%t1.o,_ZN1D1mEi, \ 107; RUN: -r=%t1.o,_ZN1D1mEi, \ 108; RUN: -r=%t1.o,test2, \ 109; RUN: -r=%t2.o,_ZN1A1nEi,p \ 110; RUN: -r=%t2.o,_ZN1B1fEi,p \ 111; RUN: -r=%t2.o,_ZN1C1fEi,p \ 112; RUN: -r=%t2.o,_ZN1D1mEi,p \ 113; RUN: -r=%t2.o,_ZN1E1mEi,p \ 114; RUN: -r=%t2.o,_ZTV1B, \ 115; RUN: -r=%t2.o,_ZTV1C, \ 116; RUN: -r=%t2.o,_ZTV1D, \ 117; RUN: -r=%t2.o,_ZTV1E, \ 118; RUN: -r=%t2.o,test2,px \ 119; RUN: -r=%t2.o,_ZN1A1nEi, \ 120; RUN: -r=%t2.o,_ZN1B1fEi, \ 121; RUN: -r=%t2.o,_ZN1C1fEi, \ 122; RUN: -r=%t2.o,_ZN1D1mEi, \ 123; RUN: -r=%t2.o,_ZN1E1mEi, \ 124; RUN: -r=%t2.o,_ZTV1B,px \ 125; RUN: -r=%t2.o,_ZTV1C,px \ 126; RUN: -r=%t2.o,_ZTV1D,px \ 127; RUN: -r=%t2.o,_ZTV1E,px 2>&1 | FileCheck %s --check-prefix=REMARK 128; RUN: llvm-dis %t5.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR1 129; RUN: llvm-dis %t5.2.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR2 130; RUN: llvm-nm %t5.1 | FileCheck %s --check-prefix=NM-HYBRID1 131; RUN: llvm-nm %t5.2 | FileCheck %s --check-prefix=NM-HYBRID2 132 133; NM-HYBRID1-DAG: U _ZN1A1nEi.{{[0-9a-f]*}} 134; NM-HYBRID1-DAG: U _ZN1E1mEi.{{[0-9a-f]*}} 135; NM-HYBRID1-DAG: U _ZN1D1mEi 136 137; NM-HYBRID2-DAG: T _ZN1A1nEi.{{[0-9a-f]*}} 138; NM-HYBRID2-DAG: T _ZN1E1mEi.{{[0-9a-f]*}} 139; NM-HYBRID2-DAG: W _ZN1D1mEi 140; NM-HYBRID2-DAG: T _ZN1B1fEi 141; NM-HYBRID2-DAG: T _ZN1C1fEi 142 143; REMARK-DAG: single-impl: devirtualized a call to _ZN1A1nEi 144; REMARK-DAG: single-impl: devirtualized a call to _ZN1D1mEi 145; We should devirt call to _ZN1E1mEi once in importing module and once 146; in original (exporting) module. 147; REMARK-DAG: single-impl: devirtualized a call to _ZN1E1mEi 148; REMARK-DAG: single-impl: devirtualized a call to _ZN1E1mEi 149 150target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 151target triple = "x86_64-grtev4-linux-gnu" 152 153%struct.A = type { ptr } 154%struct.B = type { %struct.A } 155%struct.C = type { %struct.A } 156%struct.D = type { ptr } 157%struct.E = type { ptr } 158 159@_ZTV1B = external constant [4 x ptr] 160@_ZTV1C = external constant [4 x ptr] 161;@_ZTV1D = external constant [3 x ptr] 162@_ZTV1D = linkonce_odr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr undef, ptr @_ZN1D1mEi] }, !type !3 163 164define linkonce_odr i32 @_ZN1D1mEi(ptr %this, i32 %a) #0 { 165 ret i32 0 166} 167 168; CHECK-IR1-LABEL: define i32 @test 169define i32 @test(ptr %obj, ptr %obj2, ptr %obj3, i32 %a) { 170entry: 171 %vtable = load ptr, ptr %obj 172 %p = call i1 @llvm.type.test(ptr %vtable, metadata !"_ZTS1A") 173 call void @llvm.assume(i1 %p) 174 %fptrptr = getelementptr ptr, ptr %vtable, i32 1 175 %fptr1 = load ptr, ptr %fptrptr, align 8 176 177 ; Check that the call was devirtualized. Ignore extra character before 178 ; symbol name which would happen if it was promoted during module 179 ; splitting for hybrid WPD. 180 ; CHECK-IR1: %call = tail call i32 @_ZN1A1nEi 181 %call = tail call i32 %fptr1(ptr nonnull %obj, i32 %a) 182 183 %fptr22 = load ptr, ptr %vtable, align 8 184 185 ; We still have to call it as virtual. 186 ; CHECK-IR1: %call3 = tail call i32 %fptr22 187 %call3 = tail call i32 %fptr22(ptr nonnull %obj, i32 %call) 188 189 %vtable2 = load ptr, ptr %obj2 190 %p2 = call i1 @llvm.type.test(ptr %vtable2, metadata !"_ZTS1D") 191 call void @llvm.assume(i1 %p2) 192 193 %fptr33 = load ptr, ptr %vtable2, align 8 194 195 ; Check that the call was devirtualized. 196 ; CHECK-IR1: %call4 = tail call i32 @_ZN1D1mEi 197 %call4 = tail call i32 %fptr33(ptr nonnull %obj2, i32 %call3) 198 199 %call5 = tail call i32 @test2(ptr nonnull %obj3, i32 %call4) 200 ret i32 %call5 201} 202; CHECK-IR1-LABEL: ret i32 203; CHECK-IR1-LABEL: } 204 205; CHECK-IR2: define noundef i32 @test2 206; CHECK-IR2-NEXT: entry: 207; Check that the call was devirtualized. Ignore extra character before 208; symbol name which would happen if it was promoted during module 209; splitting for hybrid WPD. 210; CHECK-IR2-NEXT: %call4 = tail call i32 @{{.*}}_ZN1E1mEi 211 212declare i1 @llvm.type.test(ptr, metadata) 213declare void @llvm.assume(i1) 214declare i32 @test2(ptr %obj, i32 %a) 215 216attributes #0 = { noinline optnone } 217 218!3 = !{i64 16, !"_ZTS1D"} 219