1 ; REQUIRES: x86-registered-target
3 ; Test devirtualization requiring promotion of local targets, where the
4 ; promotion is required by one devirtualization and needs to be updated
5 ; for a second devirtualization in the defining module as a post-pass
8 ; Generate unsplit module with summary for ThinLTO index-based WPD.
9 ; RUN: opt -thinlto-bc -o %t3.o %s
10 ; RUN: opt -thinlto-bc -o %t4.o %p/Inputs/devirt_promote.ll
12 ; RUN: llvm-lto2 run %t3.o %t4.o -save-temps -use-new-pm -pass-remarks=. \
13 ; RUN: -wholeprogramdevirt-print-index-based \
15 ; RUN: -r=%t3.o,test,px \
16 ; RUN: -r=%t4.o,_ZN1B1fEi,p \
17 ; RUN: -r=%t4.o,test2,px \
18 ; RUN: -r=%t4.o,_ZTV1B,px \
19 ; RUN: 2>&1 | FileCheck %s --check-prefix=REMARK --check-prefix=PRINT
20 ; RUN: llvm-dis %t5.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR1
21 ; RUN: llvm-dis %t5.2.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR2
22 ; RUN: llvm-nm %t5.1 | FileCheck %s --check-prefix=NM-INDEX1
23 ; RUN: llvm-nm %t5.2 | FileCheck %s --check-prefix=NM-INDEX2
25 ; NM-INDEX1: U _ZN1A1nEi.llvm.
27 ; Make sure that not only did _ZN1A1nEi get promoted (due to the
28 ; devirtualization in the other module) but the reference due to the
29 ; devirtualization in its defining module should be to the promoted
31 ; NM-INDEX2-NOT: U _ZN1A1nEi
32 ; NM-INDEX2: T _ZN1A1nEi.llvm.
33 ; NM-INDEX2-NOT: U _ZN1A1nEi
35 ; We should devirt call to _ZN1A1nEi once in importing module and once
36 ; in original (exporting) module.
37 ; REMARK-COUNT-2: single-impl: devirtualized a call to _ZN1A1nEi.llvm.
39 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
40 target triple = "x86_64-grtev4-linux-gnu"
42 %struct.A = type { i32 (...)** }
44 ; CHECK-IR1-LABEL: define i32 @test
45 define i32 @test(%struct.A* %obj, i32 %a) {
47 %0 = bitcast %struct.A* %obj to i8***
48 %vtable = load i8**, i8*** %0
49 %1 = bitcast i8** %vtable to i8*
50 %p = call i1 @llvm.type.test(i8* %1, metadata !"_ZTS1A")
51 call void @llvm.assume(i1 %p)
52 %fptrptr = getelementptr i8*, i8** %vtable, i32 1
53 %2 = bitcast i8** %fptrptr to i32 (%struct.A*, i32)**
54 %fptr1 = load i32 (%struct.A*, i32)*, i32 (%struct.A*, i32)** %2, align 8
56 ; Check that the call was devirtualized.
57 ; CHECK-IR1: %call = tail call i32 bitcast (void ()* @_ZN1A1nEi
58 %call = tail call i32 %fptr1(%struct.A* nonnull %obj, i32 %a)
62 ; CHECK-IR1-LABEL: ret i32
65 ; CHECK-IR2: define i32 @test2
66 ; Check that the call was devirtualized.
67 ; CHECK-IR2: %call4 = tail call i32 @_ZN1A1nEi
69 declare i1 @llvm.type.test(i8*, metadata)
70 declare void @llvm.assume(i1)
72 attributes #0 = { noinline optnone }