brintos

brintos / llvm-project-archived public Read only

0
0
Text · 9.2 KiB · dfb2f8f Raw
261 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:   -whole-program-visibility \11; RUN:   -o %t3 \12; RUN:   -r=%t2.o,test,px \13; RUN:   -r=%t2.o,test_public,px \14; RUN:   -r=%t2.o,_ZN1A1nEi,p \15; RUN:   -r=%t2.o,_ZN1B1fEi,p \16; RUN:   -r=%t2.o,_ZN1C1fEi,p \17; RUN:   -r=%t2.o,_ZN1D1mEi,p \18; RUN:   -r=%t2.o,_ZTV1B,px \19; RUN:   -r=%t2.o,_ZTV1C,px \20; RUN:   -r=%t2.o,_ZTV1D,px 2>&1 | FileCheck %s --check-prefix=REMARK21; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s --check-prefix=CHECK-TT22; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR23 24; Hybrid WPD25; Generate split module with summary for hybrid Thin/Regular LTO WPD.26; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t.o %s27; RUN: llvm-lto2 run %t.o -save-temps -pass-remarks=. \28; RUN:   -whole-program-visibility \29; RUN:   -o %t3 \30; RUN:   -r=%t.o,test,px \31; RUN:   -r=%t.o,test_public,px \32; RUN:   -r=%t.o,_ZN1A1nEi,p \33; RUN:   -r=%t.o,_ZN1B1fEi,p \34; RUN:   -r=%t.o,_ZN1C1fEi,p \35; RUN:   -r=%t.o,_ZN1D1mEi,p \36; RUN:   -r=%t.o,_ZTV1B, \37; RUN:   -r=%t.o,_ZTV1C, \38; RUN:   -r=%t.o,_ZTV1D, \39; RUN:   -r=%t.o,_ZN1A1nEi, \40; RUN:   -r=%t.o,_ZN1B1fEi, \41; RUN:   -r=%t.o,_ZN1C1fEi, \42; RUN:   -r=%t.o,_ZN1D1mEi, \43; RUN:   -r=%t.o,_ZTV1B,px \44; RUN:   -r=%t.o,_ZTV1C,px \45; RUN:   -r=%t.o,_ZTV1D,px 2>&1 | FileCheck %s --check-prefix=REMARK --dump-input=fail46; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s --check-prefix=CHECK-TT47; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR48 49; Regular LTO WPD50; RUN: opt -o %t4.o %s51; RUN: llvm-lto2 run %t4.o -save-temps -pass-remarks=. \52; RUN:   -whole-program-visibility \53; RUN:   -o %t5 \54; RUN:   -r=%t4.o,test,px \55; RUN:   -r=%t4.o,test_public,px \56; RUN:   -r=%t4.o,_ZN1A1nEi,p \57; RUN:   -r=%t4.o,_ZN1B1fEi,p \58; RUN:   -r=%t4.o,_ZN1C1fEi,p \59; RUN:   -r=%t4.o,_ZN1D1mEi,p \60; RUN:   -r=%t4.o,_ZTV1B,px \61; RUN:   -r=%t4.o,_ZTV1C,px \62; RUN:   -r=%t4.o,_ZTV1D,px 2>&1 | FileCheck %s --check-prefix=REMARK63; RUN: llvm-dis %t5.0.0.preopt.bc -o - | FileCheck %s --check-prefix=CHECK-TT64; RUN: llvm-dis %t5.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR65 66; REMARK-DAG: single-impl: devirtualized a call to _ZN1A1nEi67; REMARK-DAG: single-impl: devirtualized a call to _ZN1D1mEi68; REMARK-DAG: single-impl: devirtualized a call to _ZN1A1nEi69; REMARK-DAG: single-impl: devirtualized a call to _ZN1D1mEi70 71; Try everything again but without -whole-program-visibility to confirm72; WPD fails73 74; Index based WPD75; RUN: llvm-lto2 run %t2.o -save-temps -pass-remarks=. \76; RUN:   -o %t3 \77; RUN:   -r=%t2.o,test,px \78; RUN:   -r=%t2.o,test_public,px \79; RUN:   -r=%t2.o,_ZN1A1nEi,p \80; RUN:   -r=%t2.o,_ZN1B1fEi,p \81; RUN:   -r=%t2.o,_ZN1C1fEi,p \82; RUN:   -r=%t2.o,_ZN1D1mEi,p \83; RUN:   -r=%t2.o,_ZTV1B,px \84; RUN:   -r=%t2.o,_ZTV1C,px \85; RUN:   -r=%t2.o,_ZTV1D,px 2>&1 | FileCheck %s --implicit-check-not single-impl --allow-empty86; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s --check-prefix=CHECK-TT87; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-NODEVIRT-IR88 89; Hybrid WPD90; RUN: llvm-lto2 run %t.o -save-temps -pass-remarks=. \91; RUN:   -o %t3 \92; RUN:   -r=%t.o,test,px \93; RUN:   -r=%t.o,test_public,px \94; RUN:   -r=%t.o,_ZN1A1nEi,p \95; RUN:   -r=%t.o,_ZN1B1fEi,p \96; RUN:   -r=%t.o,_ZN1C1fEi,p \97; RUN:   -r=%t.o,_ZN1D1mEi,p \98; RUN:   -r=%t.o,_ZTV1B, \99; RUN:   -r=%t.o,_ZTV1C, \100; RUN:   -r=%t.o,_ZTV1D, \101; RUN:   -r=%t.o,_ZN1A1nEi, \102; RUN:   -r=%t.o,_ZN1B1fEi, \103; RUN:   -r=%t.o,_ZN1C1fEi, \104; RUN:   -r=%t.o,_ZN1D1mEi, \105; RUN:   -r=%t.o,_ZTV1B,px \106; RUN:   -r=%t.o,_ZTV1C,px \107; RUN:   -r=%t.o,_ZTV1D,px 2>&1 | FileCheck %s --implicit-check-not single-impl --allow-empty108; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s --check-prefix=CHECK-TT109; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-NODEVIRT-IR110 111; Regular LTO WPD112; RUN: llvm-lto2 run %t4.o -save-temps -pass-remarks=. \113; RUN:   -o %t5 \114; RUN:   -r=%t4.o,test,px \115; RUN:   -r=%t4.o,test_public,px \116; RUN:   -r=%t4.o,_ZN1A1nEi,p \117; RUN:   -r=%t4.o,_ZN1B1fEi,p \118; RUN:   -r=%t4.o,_ZN1C1fEi,p \119; RUN:   -r=%t4.o,_ZN1D1mEi,p \120; RUN:   -r=%t4.o,_ZTV1B,px \121; RUN:   -r=%t4.o,_ZTV1C,px \122; RUN:   -r=%t4.o,_ZTV1D,px 2>&1 | FileCheck %s --implicit-check-not single-impl --allow-empty123; RUN: llvm-dis %t5.0.0.preopt.bc -o - | FileCheck %s --check-prefix=CHECK-TT124; RUN: llvm-dis %t5.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-NODEVIRT-IR125 126; Try index-based WPD again with both -whole-program-visibility and127; -disable-whole-program-visibility to confirm the latter overrides128; the former and that WPD fails.129; RUN: llvm-lto2 run %t2.o -save-temps -pass-remarks=. \130; RUN:   -whole-program-visibility \131; RUN:   -disable-whole-program-visibility \132; RUN:   -o %t3 \133; RUN:   -r=%t2.o,test,px \134; RUN:   -r=%t2.o,test_public,px \135; RUN:   -r=%t2.o,_ZN1A1nEi,p \136; RUN:   -r=%t2.o,_ZN1B1fEi,p \137; RUN:   -r=%t2.o,_ZN1C1fEi,p \138; RUN:   -r=%t2.o,_ZN1D1mEi,p \139; RUN:   -r=%t2.o,_ZTV1B,px \140; RUN:   -r=%t2.o,_ZTV1C,px \141; RUN:   -r=%t2.o,_ZTV1D,px 2>&1 | FileCheck %s --implicit-check-not single-impl --allow-empty142; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s --check-prefix=CHECK-TT143; RUN: llvm-dis %t3.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-NODEVIRT-IR144 145; CHECK-TT-NOT: call {{.*}}@llvm.public.type.test146 147target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"148target triple = "x86_64-grtev4-linux-gnu"149 150%struct.A = type { ptr }151%struct.B = type { %struct.A }152%struct.C = type { %struct.A }153%struct.D = type { ptr }154 155@_ZTV1B = constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr undef, ptr @_ZN1B1fEi, ptr @_ZN1A1nEi] }, !type !0, !type !1, !vcall_visibility !5156@_ZTV1C = constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr undef, ptr @_ZN1C1fEi, ptr @_ZN1A1nEi] }, !type !0, !type !2, !vcall_visibility !5157@_ZTV1D = constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr undef, ptr @_ZN1D1mEi] }, !type !3, !vcall_visibility !5158 159 160; CHECK-IR-LABEL: define {{(noundef )?}}i32 @test161define i32 @test(ptr %obj, ptr %obj2, i32 %a) {162entry:163  %vtable = load ptr, ptr %obj164  %p = call i1 @llvm.type.test(ptr %vtable, metadata !"_ZTS1A")165  call void @llvm.assume(i1 %p)166  %fptrptr = getelementptr ptr, ptr %vtable, i32 1167  %fptr1 = load ptr, ptr %fptrptr, align 8168 169  ; Check that the call was devirtualized.170  ; CHECK-IR: %call = tail call i32 @_ZN1A1nEi171  ; CHECK-NODEVIRT-IR: %call = tail call i32 %fptr1172  %call = tail call i32 %fptr1(ptr nonnull %obj, i32 %a)173 174  %fptr22 = load ptr, ptr %vtable, align 8175 176  ; We still have to call it as virtual.177  ; CHECK-IR: %call3 = tail call i32 %fptr22178  ; CHECK-NODEVIRT-IR: %call3 = tail call i32 %fptr22179  %call3 = tail call i32 %fptr22(ptr nonnull %obj, i32 %call)180 181  %vtable2 = load ptr, ptr %obj2182  %p2 = call i1 @llvm.type.test(ptr %vtable2, metadata !4)183  call void @llvm.assume(i1 %p2)184 185  %fptr33 = load ptr, ptr %vtable2, align 8186 187  ; Check that the call was devirtualized.188  ; CHECK-IR: %call4 = tail call i32 @_ZN1D1mEi189  ; CHECK-NODEVIRT-IR: %call4 = tail call i32 %fptr33190  %call4 = tail call i32 %fptr33(ptr nonnull %obj2, i32 %call3)191  ret i32 %call4192}193; CHECK-IR-LABEL: ret i32194; CHECK-IR-LABEL: }195 196; CHECK-IR-LABEL: define {{(noundef )?}}i32 @test_public197define i32 @test_public(ptr %obj, ptr %obj2, i32 %a) {198entry:199  %vtable = load ptr, ptr %obj200  %p = call i1 @llvm.public.type.test(ptr %vtable, metadata !"_ZTS1A")201  call void @llvm.assume(i1 %p)202  %fptrptr = getelementptr ptr, ptr %vtable, i32 1203  %fptr1 = load ptr, ptr %fptrptr, align 8204 205  ; Check that the call was devirtualized.206  ; CHECK-IR: %call = tail call i32 @_ZN1A1nEi207  ; CHECK-NODEVIRT-IR: %call = tail call i32 %fptr1208  %call = tail call i32 %fptr1(ptr nonnull %obj, i32 %a)209 210  %fptr22 = load ptr, ptr %vtable, align 8211 212  ; We still have to call it as virtual.213  ; CHECK-IR: %call3 = tail call i32 %fptr22214  ; CHECK-NODEVIRT-IR: %call3 = tail call i32 %fptr22215  %call3 = tail call i32 %fptr22(ptr nonnull %obj, i32 %call)216 217  %vtable2 = load ptr, ptr %obj2218  %p2 = call i1 @llvm.public.type.test(ptr %vtable2, metadata !4)219  call void @llvm.assume(i1 %p2)220 221  %fptr33 = load ptr, ptr %vtable2, align 8222 223  ; Check that the call was devirtualized.224  ; CHECK-IR: %call4 = tail call i32 @_ZN1D1mEi225  ; CHECK-NODEVIRT-IR: %call4 = tail call i32 %fptr33226  %call4 = tail call i32 %fptr33(ptr nonnull %obj2, i32 %call3)227  ret i32 %call4228}229; CHECK-IR-LABEL: ret i32230; CHECK-IR-LABEL: }231 232declare i1 @llvm.type.test(ptr, metadata)233declare i1 @llvm.public.type.test(ptr, metadata)234declare void @llvm.assume(i1)235 236define i32 @_ZN1B1fEi(ptr %this, i32 %a) #0 {237   ret i32 0;238}239 240define i32 @_ZN1A1nEi(ptr %this, i32 %a) #0 {241   ret i32 0;242}243 244define i32 @_ZN1C1fEi(ptr %this, i32 %a) #0 {245   ret i32 0;246}247 248define i32 @_ZN1D1mEi(ptr %this, i32 %a) #0 {249   ret i32 0;250}251 252; Make sure we don't inline or otherwise optimize out the direct calls.253attributes #0 = { noinline optnone }254 255!0 = !{i64 16, !"_ZTS1A"}256!1 = !{i64 16, !"_ZTS1B"}257!2 = !{i64 16, !"_ZTS1C"}258!3 = !{i64 16, !4}259!4 = distinct !{}260!5 = !{i64 0}261