1; REQUIRES: x86-registered-target 2 3; Test that index-based devirtualization in the presence of same-named 4; local vtables in same named source files fails. 5 6; Generate unsplit module with summary for ThinLTO index-based WPD. 7; RUN: opt -thinlto-bc -o %t3.o %s 8; RUN: opt -thinlto-bc -o %t4.o %p/Inputs/devirt_local_same_guid.ll 9 10; RUN: llvm-lto2 run %t3.o %t4.o -save-temps -use-new-pm -pass-remarks=. \ 11; RUN: -wholeprogramdevirt-print-index-based \ 12; RUN: -o %t5 \ 13; RUN: -r=%t3.o,use_B,px \ 14; RUN: -r=%t3.o,test,px \ 15; RUN: -r=%t4.o,test2,px 16; RUN: llvm-dis %t5.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR1 17; RUN: llvm-dis %t5.2.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR2 18 19target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 20target triple = "x86_64-grtev4-linux-gnu" 21 22source_filename = "-" 23 24%struct.A = type { i32 (...)** } 25%struct.B = type { %struct.A } 26 27@_ZTV1B = internal constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* undef, i8* bitcast (i32 (%struct.B*, i32)* @_ZN1B1fEi to i8*), i8* bitcast (i32 (%struct.B*, i32)* @_ZN1B1nEi to i8*)] }, !type !0, !type !1 28 29define internal i32 @_ZN1B1fEi(%struct.B* %this, i32 %a) #0 { 30 ret i32 0; 31} 32 33define internal i32 @_ZN1B1nEi(%struct.B* %this, i32 %a) #0 { 34 ret i32 0; 35} 36 37; Ensures that vtable of B is live so that we will attempt devirt. 38define dso_local i32 @use_B(%struct.B* %a) { 39entry: 40 %0 = bitcast %struct.B* %a to i32 (...)*** 41 store i32 (...)** bitcast (i8** getelementptr inbounds ({ [4 x i8*] }, { [4 x i8*] }* @_ZTV1B, i64 0, inrange i32 0, i64 2) to i32 (...)**), i32 (...)*** %0, align 8 42 ret i32 0 43} 44 45; CHECK-IR1: define i32 @test( 46define i32 @test(%struct.A* %obj, i32 %a) { 47entry: 48 %0 = bitcast %struct.A* %obj to i8*** 49 %vtable = load i8**, i8*** %0 50 %1 = bitcast i8** %vtable to i8* 51 %p = call i1 @llvm.type.test(i8* %1, metadata !"_ZTS1A") 52 call void @llvm.assume(i1 %p) 53 %fptrptr = getelementptr i8*, i8** %vtable, i32 1 54 %2 = bitcast i8** %fptrptr to i32 (%struct.A*, i32)** 55 %fptr1 = load i32 (%struct.A*, i32)*, i32 (%struct.A*, i32)** %2, align 8 56 57 ; Check that the call was not devirtualized. 58 ; CHECK-IR1: %call = tail call i32 %fptr1 59 %call = tail call i32 %fptr1(%struct.A* nonnull %obj, i32 %a) 60 61 ret i32 %call 62} 63 64; CHECK-IR2: define i32 @test2 65; Check that the call was not devirtualized. 66; CHECK-IR2: %call4 = tail call i32 %fptr 67 68declare i1 @llvm.type.test(i8*, metadata) 69declare void @llvm.assume(i1) 70 71attributes #0 = { noinline optnone } 72 73!0 = !{i64 16, !"_ZTS1A"} 74!1 = !{i64 16, !"_ZTS1B"} 75