12cefb939STeresa Johnson; REQUIRES: x86-registered-target 22cefb939STeresa Johnson 32cefb939STeresa Johnson; Test that index-based devirtualization in the presence of external 42cefb939STeresa Johnson; vtables with the same name (with comdat) succeeds. 52cefb939STeresa Johnson 62cefb939STeresa Johnson; Generate unsplit module with summary for ThinLTO index-based WPD. 72cefb939STeresa Johnson; RUN: opt -thinlto-bc -o %t3.o %s 82cefb939STeresa Johnson; RUN: opt -thinlto-bc -o %t4.o %p/Inputs/devirt_external_comdat_same_guid.ll 92cefb939STeresa Johnson 10*2121dc5bSNikita Popov; RUN: llvm-lto2 run %t3.o %t4.o -save-temps -pass-remarks=. \ 112f63d549STeresa Johnson; RUN: -whole-program-visibility \ 122cefb939STeresa Johnson; RUN: -wholeprogramdevirt-print-index-based \ 132cefb939STeresa Johnson; RUN: -o %t5 \ 142cefb939STeresa Johnson; RUN: -r=%t3.o,use_B,px \ 152cefb939STeresa Johnson; RUN: -r=%t3.o,test,px \ 162cefb939STeresa Johnson; RUN: -r=%t3.o,_ZTV1B,px \ 172cefb939STeresa Johnson; RUN: -r=%t3.o,_ZN1B1fEi,px \ 182cefb939STeresa Johnson; RUN: -r=%t3.o,_ZN1B1nEi,px \ 192cefb939STeresa Johnson; RUN: -r=%t4.o,_ZTV1B,x \ 202cefb939STeresa Johnson; RUN: -r=%t4.o,_ZN1B1fEi,x \ 212cefb939STeresa Johnson; RUN: -r=%t4.o,_ZN1A1nEi,x \ 222cefb939STeresa Johnson; RUN: -r=%t4.o,test2,px \ 232cefb939STeresa Johnson; RUN: 2>&1 | FileCheck %s --check-prefix=REMARK --check-prefix=PRINT 242cefb939STeresa Johnson; RUN: llvm-dis %t5.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR1 252cefb939STeresa Johnson; RUN: llvm-dis %t5.2.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR2 262cefb939STeresa Johnson 272cefb939STeresa Johnson; PRINT-DAG: Devirtualized call to {{.*}} (_ZN1A1nEi) 282cefb939STeresa Johnson 292cefb939STeresa Johnson; REMARK-DAG: single-impl: devirtualized a call to _ZN1A1nEi 302cefb939STeresa Johnson 312cefb939STeresa Johnsontarget datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 322cefb939STeresa Johnsontarget triple = "x86_64-grtev4-linux-gnu" 332cefb939STeresa Johnson 342cefb939STeresa Johnsonsource_filename = "-" 352cefb939STeresa Johnson 362cefb939STeresa Johnson%struct.A = type { i32 (...)** } 372cefb939STeresa Johnson%struct.B = type { %struct.A } 382cefb939STeresa Johnson 392cefb939STeresa Johnson$_ZTV1B = comdat any 402cefb939STeresa Johnson 412cefb939STeresa Johnson@_ZTV1B = 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*)] }, comdat, !type !0, !type !1 422cefb939STeresa Johnson 432cefb939STeresa Johnsondefine i32 @_ZN1B1fEi(%struct.B* %this, i32 %a) #0 comdat($_ZTV1B) { 442cefb939STeresa Johnson ret i32 0; 452cefb939STeresa Johnson} 462cefb939STeresa Johnson 472cefb939STeresa Johnsondefine i32 @_ZN1B1nEi(%struct.B* %this, i32 %a) #0 comdat($_ZTV1B) { 482cefb939STeresa Johnson ret i32 0; 492cefb939STeresa Johnson} 502cefb939STeresa Johnson 512cefb939STeresa Johnson; Ensures that vtable of B is live so that we will attempt devirt. 522cefb939STeresa Johnsondefine dso_local i32 @use_B(%struct.B* %a) { 532cefb939STeresa Johnsonentry: 542cefb939STeresa Johnson %0 = bitcast %struct.B* %a to i32 (...)*** 552cefb939STeresa Johnson 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 562cefb939STeresa Johnson ret i32 0 572cefb939STeresa Johnson} 582cefb939STeresa Johnson 592cefb939STeresa Johnson; CHECK-IR1: define i32 @test( 602cefb939STeresa Johnsondefine i32 @test(%struct.A* %obj, i32 %a) { 612cefb939STeresa Johnsonentry: 622cefb939STeresa Johnson %0 = bitcast %struct.A* %obj to i8*** 632cefb939STeresa Johnson %vtable = load i8**, i8*** %0 642cefb939STeresa Johnson %1 = bitcast i8** %vtable to i8* 652cefb939STeresa Johnson %p = call i1 @llvm.type.test(i8* %1, metadata !"_ZTS1A") 662cefb939STeresa Johnson call void @llvm.assume(i1 %p) 672cefb939STeresa Johnson %fptrptr = getelementptr i8*, i8** %vtable, i32 1 682cefb939STeresa Johnson %2 = bitcast i8** %fptrptr to i32 (%struct.A*, i32)** 692cefb939STeresa Johnson %fptr1 = load i32 (%struct.A*, i32)*, i32 (%struct.A*, i32)** %2, align 8 702cefb939STeresa Johnson 712cefb939STeresa Johnson ; Check that the call was devirtualized. 722cefb939STeresa Johnson ; CHECK-IR1: tail call i32 {{.*}}@_ZN1A1nEi 732cefb939STeresa Johnson %call = tail call i32 %fptr1(%struct.A* nonnull %obj, i32 %a) 742cefb939STeresa Johnson 752cefb939STeresa Johnson ret i32 %call 762cefb939STeresa Johnson} 772cefb939STeresa Johnson 782cefb939STeresa Johnson; CHECK-IR2: define i32 @test2 792cefb939STeresa Johnson; Check that the call was devirtualized. 802cefb939STeresa Johnson; CHECK-IR2: tail call i32 @_ZN1A1nEi 812cefb939STeresa Johnson 822cefb939STeresa Johnsondeclare i1 @llvm.type.test(i8*, metadata) 832cefb939STeresa Johnsondeclare void @llvm.assume(i1) 842cefb939STeresa Johnson 852cefb939STeresa Johnsonattributes #0 = { noinline optnone } 862cefb939STeresa Johnson 872cefb939STeresa Johnson!0 = !{i64 16, !"_ZTS1A"} 882cefb939STeresa Johnson!1 = !{i64 16, !"_ZTS1B"} 89