xref: /llvm-project/llvm/test/ThinLTO/X86/devirt_promote_legacy.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-lto -thinlto-action=run %t3.o %t4.o --thinlto-save-temps=%t5. \
13; RUN:   -whole-program-visibility \
14; RUN:   --pass-remarks=. \
15; RUN:   --exported-symbol=test \
16; RUN:   --exported-symbol=test2 \
17; RUN:   --exported-symbol=_ZTV1B 2>&1 | FileCheck %s --check-prefix=REMARK
18; RUN: llvm-dis %t5.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR1
19; RUN: llvm-dis %t5.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR2
20
21; We should devirt call to _ZN1A1nEi once in importing module and once
22; in original (exporting) module.
23; REMARK-COUNT-2: single-impl: devirtualized a call to _ZN1A1nEi.llvm.
24
25target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
26target triple = "x86_64-grtev4-linux-gnu"
27
28%struct.A = type { ptr }
29
30; CHECK-IR1-LABEL: define i32 @test
31define i32 @test(ptr %obj, i32 %a) {
32entry:
33  %vtable = load ptr, ptr %obj
34  %p = call i1 @llvm.type.test(ptr %vtable, metadata !"_ZTS1A")
35  call void @llvm.assume(i1 %p)
36  %fptrptr = getelementptr ptr, ptr %vtable, i32 1
37  %fptr1 = load ptr, ptr %fptrptr, align 8
38
39  ; Check that the call was devirtualized.
40  ; CHECK-IR1: = tail call i32 @_ZN1A1nEi
41  %call = tail call i32 %fptr1(ptr nonnull %obj, i32 %a)
42
43  ret i32 %call
44}
45; CHECK-IR1-LABEL: ret i32
46; CHECK-IR1-LABEL: }
47
48; CHECK-IR2: define noundef i32 @test2
49; Check that the call was devirtualized.
50; CHECK-IR2: = tail call i32 @_ZN1A1nEi
51
52declare i1 @llvm.type.test(ptr, metadata)
53declare void @llvm.assume(i1)
54
55attributes #0 = { noinline optnone }
56