1; REQUIRES: x86-registered-target 2 3;; Check for successful devirtualization when vtable contains an alias, 4;; and there is a single implementation. 5 6;; Test pure ThinLTO 7 8;; Generate unsplit module with summary for ThinLTO index-based WPD. 9; RUN: opt -thinlto-bc -o %t1.o %s 10 11;; Check that we have properly recorded the alias in the vtable summary. 12; RUN: llvm-dis -o - %t1.o | FileCheck %s --check-prefix SUMMARY 13; SUMMARY: gv: (name: "_ZTV1D", {{.*}} vTableFuncs: ((virtFunc: ^[[ALIAS:([0-9]+)]], offset: 16)) 14; SUMMARY: ^[[ALIAS]] = gv: (name: "_ZN1D1mEiAlias" 15 16; RUN: llvm-lto2 run %t1.o -save-temps -pass-remarks=. \ 17; RUN: -whole-program-visibility \ 18; RUN: -wholeprogramdevirt-print-index-based \ 19; RUN: -o %t2 \ 20; RUN: -r=%t1.o,test,px \ 21; RUN: -r=%t1.o,_ZTV1D,px \ 22; RUN: -r=%t1.o,_ZN1D1mEi,px \ 23; RUN: -r=%t1.o,_ZN1D1mEiAlias,px \ 24; RUN: 2>&1 | FileCheck %s --check-prefix=REMARK --check-prefix=PRINT 25; RUN: llvm-dis %t2.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR1 26 27; PRINT-DAG: Devirtualized call to {{.*}} (_ZN1D1mEiAlias) 28; REMARK-DAG: single-impl: devirtualized a call to _ZN1D1mEiAlias 29 30;; Test hybrid Thin/Regular LTO 31 32;; Generate split module with summary for hybrid Thin/Regular LTO WPD. 33; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t3.o %s 34 35; RUN: llvm-lto2 run %t3.o -save-temps -pass-remarks=. \ 36; RUN: -whole-program-visibility \ 37; RUN: -o %t4 \ 38; RUN: -r=%t3.o,test,px \ 39; RUN: -r=%t3.o,_ZTV1D, \ 40; RUN: -r=%t3.o,_ZTV1D,px \ 41; RUN: -r=%t3.o,_ZN1D1mEi,px \ 42; RUN: -r=%t3.o,_ZN1D1mEiAlias,px \ 43; RUN: -r=%t3.o,_ZN1D1mEiAlias, \ 44; RUN: 2>&1 | FileCheck %s --check-prefix=REMARK 45; RUN: llvm-dis %t4.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR1 46 47;; Test Regular LTO 48; RUN: opt -o %t5.o %s 49; RUN: llvm-lto2 run %t5.o -save-temps -pass-remarks=. \ 50; RUN: -whole-program-visibility \ 51; RUN: -o %t6 \ 52; RUN: -r=%t5.o,test,px \ 53; RUN: -r=%t5.o,_ZTV1D,px \ 54; RUN: -r=%t5.o,_ZN1D1mEi,px \ 55; RUN: -r=%t5.o,_ZN1D1mEiAlias,px \ 56; RUN: 2>&1 | FileCheck %s --check-prefix=REMARK 57; RUN: llvm-dis %t6.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR1 58 59target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 60target triple = "x86_64-grtev4-linux-gnu" 61 62%struct.D = type { ptr } 63 64@_ZTV1D = constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr undef, ptr @_ZN1D1mEiAlias] }, !type !3 65 66define i32 @_ZN1D1mEi(ptr %this, i32 %a) { 67 ret i32 0; 68} 69 70@_ZN1D1mEiAlias = unnamed_addr alias i32 (ptr, i32), ptr @_ZN1D1mEi 71 72; CHECK-IR1-LABEL: define i32 @test 73define i32 @test(ptr %obj2, i32 %a) { 74entry: 75 %vtable2 = load ptr, ptr %obj2 76 %p2 = call i1 @llvm.type.test(ptr %vtable2, metadata !"_ZTS1D") 77 call void @llvm.assume(i1 %p2) 78 79 %fptr33 = load ptr, ptr %vtable2, align 8 80 81 ;; Check that the call was devirtualized. 82 ;; CHECK-IR1: %call4 = tail call i32 @_ZN1D1mEi 83 %call4 = tail call i32 %fptr33(ptr nonnull %obj2, i32 %a) 84 ret i32 %call4 85} 86; CHECK-IR1-LABEL: ret i32 87; CHECK-IR1-LABEL: } 88 89declare i1 @llvm.type.test(ptr, metadata) 90declare void @llvm.assume(i1) 91 92!3 = !{i64 16, !"_ZTS1D"} 93