141 lines · plain
1;; Test that plugin option whole-program-visibility enables devirtualization.2 3;; Index based WPD4;; Generate unsplit module with summary for ThinLTO index-based WPD.5; RUN: opt -thinlto-bc -o %t2.o %s6; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \7; RUN: --plugin-opt=whole-program-visibility \8; RUN: --plugin-opt=save-temps \9; RUN: --plugin-opt=-pass-remarks=. \10; RUN: %t2.o -o %t3 2>&1 | FileCheck %s --check-prefix=REMARK11; RUN: llvm-dis %t2.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR12 13;; Hybrid WPD14;; Generate split module with summary for hybrid Thin/Regular LTO WPD.15; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t.o %s16; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \17; RUN: --plugin-opt=whole-program-visibility \18; RUN: --plugin-opt=save-temps \19; RUN: --plugin-opt=-pass-remarks=. \20; RUN: %t.o -o %t3 2>&1 | FileCheck %s --check-prefix=REMARK21; RUN: llvm-dis %t.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR22 23;; Regular LTO WPD24; RUN: opt -o %t4.o %s25; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \26; RUN: --plugin-opt=whole-program-visibility \27; RUN: --plugin-opt=save-temps \28; RUN: --plugin-opt=-pass-remarks=. \29; RUN: %t4.o -o %t3 2>&1 | FileCheck %s --check-prefix=REMARK30; RUN: llvm-dis %t3.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR31 32; REMARK-DAG: single-impl: devirtualized a call to _ZN1A1nEi33; REMARK-DAG: single-impl: devirtualized a call to _ZN1D1mEi34 35;; Try everything again but without -whole-program-visibility to confirm36;; WPD fails37 38;; Index based WPD39; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \40; RUN: --plugin-opt=save-temps \41; RUN: --plugin-opt=-pass-remarks=. \42; RUN: %t2.o -o %t3 \43; RUN: 2>&1 | FileCheck /dev/null --implicit-check-not single-impl --allow-empty44; RUN: llvm-dis %t2.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-NODEVIRT-IR45 46;; Hybrid WPD47; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \48; RUN: --plugin-opt=save-temps \49; RUN: --plugin-opt=-pass-remarks=. \50; RUN: %t.o -o %t3 \51; RUN: 2>&1 | FileCheck /dev/null --implicit-check-not single-impl --allow-empty52; RUN: llvm-dis %t.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-NODEVIRT-IR53 54;; Regular LTO WPD55; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \56; RUN: --plugin-opt=save-temps \57; RUN: --plugin-opt=-pass-remarks=. \58; RUN: %t4.o -o %t3 \59; RUN: 2>&1 | FileCheck /dev/null --implicit-check-not single-impl --allow-empty60; RUN: llvm-dis %t3.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-NODEVIRT-IR61 62target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"63target triple = "x86_64-grtev4-linux-gnu"64 65%struct.A = type { ptr }66%struct.B = type { %struct.A }67%struct.C = type { %struct.A }68%struct.D = type { ptr }69 70@_ZTV1B = constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr undef, ptr @_ZN1B1fEi, ptr @_ZN1A1nEi] }, !type !0, !type !1, !vcall_visibility !571@_ZTV1C = constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr undef, ptr @_ZN1C1fEi, ptr @_ZN1A1nEi] }, !type !0, !type !2, !vcall_visibility !572@_ZTV1D = constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr undef, ptr @_ZN1D1mEi] }, !type !3, !vcall_visibility !573 74; Prevent the vtables from being dead code eliminated.75@llvm.used = appending global [3 x ptr] [ ptr @_ZTV1B, ptr @_ZTV1C, ptr @_ZTV1D]76 77; CHECK-IR-LABEL: define dso_local {{(noundef )?}}i32 @_start78define i32 @_start(ptr %obj, ptr %obj2, i32 %a) {79entry:80 %vtable = load ptr, ptr %obj81 %p = call i1 @llvm.type.test(ptr %vtable, metadata !"_ZTS1A")82 call void @llvm.assume(i1 %p)83 %fptrptr = getelementptr ptr, ptr %vtable, i32 184 %fptr1 = load ptr, ptr %fptrptr, align 885 86 ;; Check that the call was devirtualized.87 ; CHECK-IR: %call = tail call i32 @_ZN1A1nEi88 ; CHECK-NODEVIRT-IR: %call = tail call i32 %fptr189 %call = tail call i32 %fptr1(ptr nonnull %obj, i32 %a)90 91 %fptr22 = load ptr, ptr %vtable, align 892 93 ;; We still have to call it as virtual.94 ; CHECK-IR: %call3 = tail call i32 %fptr2295 ; CHECK-NODEVIRT-IR: %call3 = tail call i32 %fptr2296 %call3 = tail call i32 %fptr22(ptr nonnull %obj, i32 %call)97 98 %vtable2 = load ptr, ptr %obj299 %p2 = call i1 @llvm.type.test(ptr %vtable2, metadata !4)100 call void @llvm.assume(i1 %p2)101 102 %fptr33 = load ptr, ptr %vtable2, align 8103 104 ;; Check that the call was devirtualized.105 ; CHECK-IR: %call4 = tail call i32 @_ZN1D1mEi106 ; CHECK-NODEVIRT-IR: %call4 = tail call i32 %fptr33107 %call4 = tail call i32 %fptr33(ptr nonnull %obj2, i32 %call3)108 ret i32 %call4109}110; CHECK-IR-LABEL: ret i32111; CHECK-IR-LABEL: }112 113declare i1 @llvm.type.test(ptr, metadata)114declare void @llvm.assume(i1)115 116define i32 @_ZN1B1fEi(ptr %this, i32 %a) #0 {117 ret i32 0;118}119 120define i32 @_ZN1A1nEi(ptr %this, i32 %a) #0 {121 ret i32 0;122}123 124define i32 @_ZN1C1fEi(ptr %this, i32 %a) #0 {125 ret i32 0;126}127 128define i32 @_ZN1D1mEi(ptr %this, i32 %a) #0 {129 ret i32 0;130}131 132;; Make sure we don't inline or otherwise optimize out the direct calls.133attributes #0 = { noinline optnone }134 135!0 = !{i64 16, !"_ZTS1A"}136!1 = !{i64 16, !"_ZTS1B"}137!2 = !{i64 16, !"_ZTS1C"}138!3 = !{i64 16, !4}139!4 = distinct !{}140!5 = !{i64 0}141