1 ; REQUIRES: x86-registered-target
3 ;; Ensure we don't incorrectly devirtualization when one vtable contains an
4 ;; alias (i.e. ensure analysis does not improperly ignore this 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: -r=%t1.o,_ZTV1B,px \
25 ; RUN: -r=%t1.o,_ZN1B1mEi,px \
26 ; RUN: 2>&1 | FileCheck %s --implicit-check-not {{[Dd]}}evirtualized --allow-empty
27 ; RUN: llvm-dis %t2.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
29 ;; Test hybrid Thin/Regular LTO
31 ;; Generate split module with summary for hybrid Thin/Regular LTO WPD.
32 ; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t3.o %s
34 ; RUN: llvm-lto2 run %t3.o -save-temps -pass-remarks=. \
35 ; RUN: -whole-program-visibility \
37 ; RUN: -r=%t3.o,test,px \
38 ; RUN: -r=%t3.o,_ZTV1D, \
39 ; RUN: -r=%t3.o,_ZTV1D,px \
40 ; RUN: -r=%t3.o,_ZN1D1mEi,px \
41 ; RUN: -r=%t3.o,_ZN1D1mEiAlias,px \
42 ; RUN: -r=%t3.o,_ZN1D1mEiAlias, \
43 ; RUN: -r=%t3.o,_ZTV1B, \
44 ; RUN: -r=%t3.o,_ZTV1B,px \
45 ; RUN: -r=%t3.o,_ZN1B1mEi,px \
46 ; RUN: -r=%t3.o,_ZN1B1mEi, \
47 ; RUN: 2>&1 | FileCheck %s --implicit-check-not {{[Dd]}}evirtualized --allow-empty
48 ; RUN: llvm-dis %t4.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
52 ; RUN: opt -o %t5.o %s
53 ; RUN: llvm-lto2 run %t5.o -save-temps -pass-remarks=. \
54 ; RUN: -whole-program-visibility \
56 ; RUN: -r=%t5.o,test,px \
57 ; RUN: -r=%t5.o,_ZTV1D,px \
58 ; RUN: -r=%t5.o,_ZN1D1mEi,px \
59 ; RUN: -r=%t5.o,_ZN1D1mEiAlias,px \
60 ; RUN: -r=%t5.o,_ZTV1B,px \
61 ; RUN: -r=%t5.o,_ZN1B1mEi,px \
62 ; RUN: 2>&1 | FileCheck %s --implicit-check-not {{[Dd]}}evirtualized --allow-empty
63 ; RUN: llvm-dis %t6.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR
65 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
66 target triple = "x86_64-grtev4-linux-gnu"
68 %struct.D = type { ptr }
69 %struct.B = type { %struct.D }
71 @_ZTV1D = constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr undef, ptr @_ZN1D1mEiAlias] }, !type !0
72 @_ZTV1B = constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr undef, ptr @_ZN1B1mEi] }, !type !0, !type !1
75 define i32 @_ZN1D1mEi(ptr %this, i32 %a) {
79 @_ZN1D1mEiAlias = unnamed_addr alias i32 (ptr, i32), ptr @_ZN1D1mEi
81 define i32 @_ZN1B1mEi(ptr %this, i32 %a) {
85 ; CHECK-IR-LABEL: define i32 @test
86 define i32 @test(ptr %obj2, i32 %a) {
88 %vtable2 = load ptr, ptr %obj2
89 %p2 = call i1 @llvm.type.test(ptr %vtable2, metadata !"_ZTS1D")
90 call void @llvm.assume(i1 %p2)
92 %fptr33 = load ptr, ptr %vtable2, align 8
94 ;; Confirm the call was not devirtualized.
95 ;; CHECK-IR: %call4 = tail call i32 %fptr33
96 %call4 = tail call i32 %fptr33(ptr nonnull %obj2, i32 %a)
99 ; CHECK-IR-LABEL: ret i32
102 declare i1 @llvm.type.test(ptr, metadata)
103 declare void @llvm.assume(i1)
105 !0 = !{i64 16, !"_ZTS1D"}
106 !1 = !{i64 16, !"_ZTS1B"}