xref: /llvm-project/llvm/test/ThinLTO/X86/devirt_promote.ll (revision 1228becf7df28c68579f2b9b390b74aa41149a0a)
1; REQUIRES: x86-registered-target
2
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
6; update.
7
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
11
12; RUN: llvm-lto2 run %t3.o %t4.o -save-temps -pass-remarks=. \
13; RUN:   -whole-program-visibility \
14; RUN:   -wholeprogramdevirt-print-index-based \
15; RUN:   -o %t5 \
16; RUN:   -r=%t3.o,test,px \
17; RUN:   -r=%t4.o,_ZN1B1fEi,p \
18; RUN:   -r=%t4.o,test2,px \
19; RUN:   -r=%t4.o,_ZTV1B,px \
20; RUN:   2>&1 | FileCheck %s --check-prefix=REMARK --check-prefix=PRINT
21; RUN: llvm-dis %t5.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR1
22; RUN: llvm-dis %t5.2.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR2
23; RUN: llvm-nm %t5.1 | FileCheck %s --check-prefix=NM-INDEX1
24; RUN: llvm-nm %t5.2 | FileCheck %s --check-prefix=NM-INDEX2
25
26; NM-INDEX1: U _ZN1A1nEi.llvm.
27
28; Make sure that not only did _ZN1A1nEi get promoted (due to the
29; devirtualization in the other module) but the reference due to the
30; devirtualization in its defining module should be to the promoted
31; symbol.
32; NM-INDEX2-NOT: U _ZN1A1nEi
33; NM-INDEX2: T _ZN1A1nEi.llvm.
34; NM-INDEX2-NOT: U _ZN1A1nEi
35
36; The thin link devirtualizes all calls to _ZN1A1nEi.
37; PRINT: Devirtualized call to {{.*}} (_ZN1A1nEi)
38
39; We should devirt call to _ZN1A1nEi once in importing module and once
40; in original (exporting) module.
41; REMARK-COUNT-2: single-impl: devirtualized a call to _ZN1A1nEi.llvm.
42
43target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
44target triple = "x86_64-grtev4-linux-gnu"
45
46%struct.A = type { ptr }
47
48; CHECK-IR1-LABEL: define i32 @test
49define i32 @test(ptr %obj, i32 %a) {
50entry:
51  %vtable = load ptr, ptr %obj
52  %p = call i1 @llvm.type.test(ptr %vtable, metadata !"_ZTS1A")
53  call void @llvm.assume(i1 %p)
54  %fptrptr = getelementptr ptr, ptr %vtable, i32 1
55  %fptr1 = load ptr, ptr %fptrptr, align 8
56
57  ; Check that the call was devirtualized.
58  ; CHECK-IR1: %call = tail call i32 @_ZN1A1nEi
59  %call = tail call i32 %fptr1(ptr nonnull %obj, i32 %a)
60
61  ret i32 %call
62}
63; CHECK-IR1-LABEL: ret i32
64; CHECK-IR1-LABEL: }
65
66; CHECK-IR2: define noundef i32 @test2
67; Check that the call was devirtualized.
68; CHECK-IR2:   %call4 = tail call i32 @_ZN1A1nEi
69
70declare i1 @llvm.type.test(ptr, metadata)
71declare void @llvm.assume(i1)
72
73attributes #0 = { noinline optnone }
74