1 ; REQUIRES: x86-registered-target
3 ;; Check for successful devirtualization when vtable contains an alias,
4 ;; and there is a single implementation.
8 ;; Generate unsplit module with summary for ThinLTO index-based WPD.
9 ; RUN: opt -thinlto-bc -o %t1.o %s
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"
16 ; RUN: llvm-lto2 run %t1.o -save-temps -pass-remarks=. \
17 ; RUN: -whole-program-visibility \
18 ; RUN: -wholeprogramdevirt-print-index-based \
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
27 ; PRINT-DAG: Devirtualized call to {{.*}} (_ZN1D1mEiAlias)
28 ; REMARK-DAG: single-impl: devirtualized a call to _ZN1D1mEiAlias
30 ;; Test hybrid Thin/Regular LTO
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
35 ; RUN: llvm-lto2 run %t3.o -save-temps -pass-remarks=. \
36 ; RUN: -whole-program-visibility \
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
48 ; RUN: opt -o %t5.o %s
49 ; RUN: llvm-lto2 run %t5.o -save-temps -pass-remarks=. \
50 ; RUN: -whole-program-visibility \
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
59 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
60 target triple = "x86_64-grtev4-linux-gnu"
62 %struct.D = type { ptr }
64 @_ZTV1D = constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr undef, ptr @_ZN1D1mEiAlias] }, !type !3
66 define i32 @_ZN1D1mEi(ptr %this, i32 %a) {
70 @_ZN1D1mEiAlias = unnamed_addr alias i32 (ptr, i32), ptr @_ZN1D1mEi
72 ; CHECK-IR1-LABEL: define i32 @test
73 define i32 @test(ptr %obj2, i32 %a) {
75 %vtable2 = load ptr, ptr %obj2
76 %p2 = call i1 @llvm.type.test(ptr %vtable2, metadata !"_ZTS1D")
77 call void @llvm.assume(i1 %p2)
79 %fptr33 = load ptr, ptr %vtable2, align 8
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)
86 ; CHECK-IR1-LABEL: ret i32
89 declare i1 @llvm.type.test(ptr, metadata)
90 declare void @llvm.assume(i1)
92 !3 = !{i64 16, !"_ZTS1D"}