1;; Test that --export-dynamic-symbol and --dynamic-list prevents devirtualization. 2;; Note that --export-dynamic is tested in the parent directory, as it does not 3;; require a more recent version of gold. 4 5;; First check that we get devirtualization without any export dynamic options. 6 7;; Index based WPD 8;; Generate unsplit module with summary for ThinLTO index-based WPD. 9; RUN: opt -thinlto-bc -o %t2.o %s 10; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \ 11; RUN: --plugin-opt=whole-program-visibility \ 12; RUN: --plugin-opt=save-temps \ 13; RUN: --plugin-opt=-pass-remarks=. \ 14; RUN: %t2.o -o %t3 2>&1 | FileCheck %s --check-prefix=REMARK 15; RUN: llvm-dis %t2.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR 16 17;; Hybrid WPD 18;; Generate split module with summary for hybrid Thin/Regular LTO WPD. 19; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t.o %s 20; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \ 21; RUN: --plugin-opt=whole-program-visibility \ 22; RUN: --plugin-opt=save-temps \ 23; RUN: --plugin-opt=-pass-remarks=. \ 24; RUN: %t.o -o %t3 2>&1 | FileCheck %s --check-prefix=REMARK 25; RUN: llvm-dis %t.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR 26 27;; Regular LTO WPD 28; RUN: opt -o %t4.o %s 29; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \ 30; RUN: --plugin-opt=whole-program-visibility \ 31; RUN: --plugin-opt=save-temps \ 32; RUN: --plugin-opt=-pass-remarks=. \ 33; RUN: %t4.o -o %t3 2>&1 | FileCheck %s --check-prefix=REMARK 34; RUN: llvm-dis %t3.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR 35 36; REMARK-DAG: single-impl: devirtualized a call to _ZN1A1nEi 37; REMARK-DAG: single-impl: devirtualized a call to _ZN1D1mEi 38 39;; Check that WPD fails for target _ZN1D1mEi with --export-dynamic-symbol=_ZTV1D. 40 41;; Index based WPD 42; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \ 43; RUN: --plugin-opt=whole-program-visibility \ 44; RUN: --plugin-opt=save-temps \ 45; RUN: --plugin-opt=-pass-remarks=. \ 46; RUN: %t2.o -o %t3 \ 47; RUN: --export-dynamic-symbol=_ZTV1D 2>&1 | FileCheck %s --check-prefix=REMARK-AONLY 48; RUN: llvm-dis %t2.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-AONLY-IR 49 50;; Hybrid WPD 51; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \ 52; RUN: --plugin-opt=whole-program-visibility \ 53; RUN: --plugin-opt=save-temps \ 54; RUN: --plugin-opt=-pass-remarks=. \ 55; RUN: %t.o -o %t3 \ 56; RUN: --export-dynamic-symbol=_ZTV1D 2>&1 | FileCheck %s --check-prefix=REMARK-AONLY 57; RUN: llvm-dis %t.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-AONLY-IR 58 59;; Regular LTO WPD 60; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \ 61; RUN: --plugin-opt=whole-program-visibility \ 62; RUN: --plugin-opt=save-temps \ 63; RUN: --plugin-opt=-pass-remarks=. \ 64; RUN: %t4.o -o %t3 \ 65; RUN: --export-dynamic-symbol=_ZTV1D 2>&1 | FileCheck %s --check-prefix=REMARK-AONLY 66; RUN: llvm-dis %t3.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-AONLY-IR 67 68; REMARK-AONLY-NOT: single-impl: 69; REMARK-AONLY: single-impl: devirtualized a call to _ZN1A1nEi 70; REMARK-AONLY-NOT: single-impl: 71 72;; Check that WPD fails for target _ZN1D1mEi with _ZTV1D in --dynamic-list. 73; RUN: echo "{ _ZTV1D; };" > %t.list 74 75;; Index based WPD 76; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \ 77; RUN: --plugin-opt=whole-program-visibility \ 78; RUN: --plugin-opt=save-temps \ 79; RUN: --plugin-opt=-pass-remarks=. \ 80; RUN: %t2.o -o %t3 \ 81; RUN: --dynamic-list=%t.list 2>&1 | FileCheck %s --check-prefix=REMARK-AONLY 82; RUN: llvm-dis %t2.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-AONLY-IR 83 84;; Hybrid WPD 85; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \ 86; RUN: --plugin-opt=whole-program-visibility \ 87; RUN: --plugin-opt=save-temps \ 88; RUN: --plugin-opt=-pass-remarks=. \ 89; RUN: %t.o -o %t3 \ 90; RUN: --dynamic-list=%t.list 2>&1 | FileCheck %s --check-prefix=REMARK-AONLY 91; RUN: llvm-dis %t.o.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-AONLY-IR 92 93;; Regular LTO WPD 94; RUN: %gold -m elf_x86_64 -plugin %llvmshlibdir/LLVMgold%shlibext \ 95; RUN: --plugin-opt=whole-program-visibility \ 96; RUN: --plugin-opt=save-temps \ 97; RUN: --plugin-opt=-pass-remarks=. \ 98; RUN: %t4.o -o %t3 \ 99; RUN: --dynamic-list=%t.list 2>&1 | FileCheck %s --check-prefix=REMARK-AONLY 100; RUN: llvm-dis %t3.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-AONLY-IR 101 102target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 103target triple = "x86_64-grtev4-linux-gnu" 104 105%struct.A = type { ptr } 106%struct.B = type { %struct.A } 107%struct.C = type { %struct.A } 108%struct.D = type { ptr } 109 110@_ZTV1B = linkonce_odr unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr undef, ptr @_ZN1B1fEi, ptr @_ZN1A1nEi] }, !type !0, !type !1, !vcall_visibility !5 111@_ZTV1C = linkonce_odr unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr undef, ptr @_ZN1C1fEi, ptr @_ZN1A1nEi] }, !type !0, !type !2, !vcall_visibility !5 112@_ZTV1D = linkonce_odr unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr undef, ptr @_ZN1D1mEi] }, !type !3, !vcall_visibility !5 113 114;; Prevent the vtables from being dead code eliminated. 115@llvm.used = appending global [3 x ptr] [ ptr @_ZTV1B, ptr @_ZTV1C, ptr @_ZTV1D] 116 117; CHECK-IR-LABEL: define dso_local {{(noundef )?}}i32 @_start 118define i32 @_start(ptr %obj, ptr %obj2, i32 %a) { 119entry: 120 %vtable = load ptr, ptr %obj 121 %p = call i1 @llvm.type.test(ptr %vtable, metadata !"_ZTS1A") 122 call void @llvm.assume(i1 %p) 123 %fptrptr = getelementptr ptr, ptr %vtable, i32 1 124 %fptr1 = load ptr, ptr %fptrptr, align 8 125 126 ;; Check that the call was devirtualized. 127 ; CHECK-IR: %call = tail call i32 @_ZN1A1nEi 128 ; CHECK-AONLY-IR: %call = tail call i32 @_ZN1A1nEi 129 %call = tail call i32 %fptr1(ptr nonnull %obj, i32 %a) 130 131 %fptr22 = load ptr, ptr %vtable, align 8 132 133 ;; We still have to call it as virtual. 134 ; CHECK-IR: %call3 = tail call i32 %fptr22 135 ; CHECK-AONLY-IR: %call3 = tail call i32 %fptr22 136 %call3 = tail call i32 %fptr22(ptr nonnull %obj, i32 %call) 137 138 %vtable2 = load ptr, ptr %obj2 139 %p2 = call i1 @llvm.type.test(ptr %vtable2, metadata !4) 140 call void @llvm.assume(i1 %p2) 141 142 %fptr33 = load ptr, ptr %vtable2, align 8 143 144 ;; Check that the call was devirtualized. 145 ; CHECK-IR: %call4 = tail call i32 @_ZN1D1mEi 146 ; CHECK-AONLY-IR: %call4 = tail call i32 %fptr33 147 %call4 = tail call i32 %fptr33(ptr nonnull %obj2, i32 %call3) 148 ret i32 %call4 149} 150; CHECK-IR-LABEL: ret i32 151; CHECK-IR-LABEL: } 152 153declare i1 @llvm.type.test(ptr, metadata) 154declare void @llvm.assume(i1) 155 156define i32 @_ZN1B1fEi(ptr %this, i32 %a) #0 { 157 ret i32 0; 158} 159 160define i32 @_ZN1A1nEi(ptr %this, i32 %a) #0 { 161 ret i32 0; 162} 163 164define i32 @_ZN1C1fEi(ptr %this, i32 %a) #0 { 165 ret i32 0; 166} 167 168define i32 @_ZN1D1mEi(ptr %this, i32 %a) #0 { 169 ret i32 0; 170} 171 172;; Make sure we don't inline or otherwise optimize out the direct calls. 173attributes #0 = { noinline optnone } 174 175!0 = !{i64 16, !"_ZTS1A"} 176!1 = !{i64 16, !"_ZTS1B"} 177!2 = !{i64 16, !"_ZTS1C"} 178!3 = !{i64 16, !4} 179!4 = distinct !{} 180!5 = !{i64 0} 181