1; REQUIRES: x86-registered-target
2
3; Test index-based devirtualization when first copy is available_externally,
4; which doesn't have type metadata. We should use the strong external
5; def in the other module to devirtualize.
6
7; Generate unsplit module with summary for ThinLTO index-based WPD.
8; RUN: opt -thinlto-bc -o %t3.o %s
9; RUN: opt -thinlto-bc -o %t4.o %p/Inputs/devirt_available_externally.ll
10
11; The available_externally copy should not get vTableFuncs information in its
12; summary entry, but the external def should.
13; RUN: llvm-dis -o - %t3.o | FileCheck %s --check-prefix=AVAILEXTERNAL
14; AVAILEXTERNAL: gv: (name: "_ZTV1D"
15; AVAILEXTERNAL-NOT: vTableFuncs
16; AVAILEXTERNAL-SAME: ; guid =
17; RUN: llvm-dis -o - %t4.o | FileCheck %s --check-prefix=EXTERNAL
18; EXTERNAL: gv: (name: "_ZTV1D", {{.*}} vTableFuncs: ((virtFunc:
19
20; RUN: llvm-lto2 run %t3.o %t4.o -save-temps -pass-remarks=. \
21; RUN:   -whole-program-visibility \
22; RUN:   -wholeprogramdevirt-print-index-based \
23; RUN:   -o %t5 \
24; RUN:   -r=%t3.o,test,px \
25; RUN:   -r=%t3.o,_ZTV1D, \
26; RUN:   -r=%t3.o,_ZN1D1mEi, \
27; RUN:   -r=%t4.o,_ZN1D1mEi,p \
28; RUN:   -r=%t4.o,_ZTV1D,px \
29; RUN:   2>&1 | FileCheck %s --check-prefix=REMARK --check-prefix=PRINT
30; RUN: llvm-dis %t5.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR1
31; RUN: llvm-nm %t5.1 | FileCheck %s --check-prefix=NM-INDEX1
32; RUN: llvm-nm %t5.2 | FileCheck %s --check-prefix=NM-INDEX2
33
34; NM-INDEX1-DAG: U _ZN1D1mEi
35
36; NM-INDEX2-DAG: T _ZN1D1mEi
37
38; PRINT-DAG: Devirtualized call to {{.*}} (_ZN1D1mEi)
39
40; REMARK-DAG: single-impl: devirtualized a call to _ZN1D1mEi
41
42target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
43target triple = "x86_64-grtev4-linux-gnu"
44
45%struct.D = type { i32 (...)** }
46
47@_ZTV1D = available_externally constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* undef, i8* bitcast (i32 (%struct.D*, i32)* @_ZN1D1mEi to i8*)] }
48
49; CHECK-IR1-LABEL: define i32 @test
50define i32 @test(%struct.D* %obj2, i32 %a) {
51entry:
52  %0 = bitcast %struct.D* %obj2 to i8***
53  %vtable2 = load i8**, i8*** %0
54  %1 = bitcast i8** %vtable2 to i8*
55  %p2 = call i1 @llvm.type.test(i8* %1, metadata !"_ZTS1D")
56  call void @llvm.assume(i1 %p2)
57
58  %2 = bitcast i8** %vtable2 to i32 (%struct.D*, i32)**
59  %fptr33 = load i32 (%struct.D*, i32)*, i32 (%struct.D*, i32)** %2, align 8
60
61  ; Check that the call was devirtualized.
62  ; CHECK-IR1: %call4 = tail call i32 @_ZN1D1mEi
63  %call4 = tail call i32 %fptr33(%struct.D* nonnull %obj2, i32 %a)
64  ret i32 %call4
65}
66; CHECK-IR1-LABEL: ret i32
67; CHECK-IR1-LABEL: }
68
69declare i1 @llvm.type.test(i8*, metadata)
70declare void @llvm.assume(i1)
71declare i32 @_ZN1D1mEi(%struct.D* %this, i32 %a)
72
73attributes #0 = { noinline optnone }
74