1; REQUIRES: x86-registered-target 2 3; Test that index-based devirtualization in the presence of external 4; vtables with the same name (with comdat) succeeds. 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_external_comdat_same_guid.ll 9 10; RUN: llvm-lto2 run %t3.o %t4.o -save-temps -use-new-pm -pass-remarks=. \ 11; RUN: -whole-program-visibility \ 12; RUN: -wholeprogramdevirt-print-index-based \ 13; RUN: -o %t5 \ 14; RUN: -r=%t3.o,use_B,px \ 15; RUN: -r=%t3.o,test,px \ 16; RUN: -r=%t3.o,_ZTV1B,px \ 17; RUN: -r=%t3.o,_ZN1B1fEi,px \ 18; RUN: -r=%t3.o,_ZN1B1nEi,px \ 19; RUN: -r=%t4.o,_ZTV1B,x \ 20; RUN: -r=%t4.o,_ZN1B1fEi,x \ 21; RUN: -r=%t4.o,_ZN1A1nEi,x \ 22; RUN: -r=%t4.o,test2,px \ 23; RUN: 2>&1 | FileCheck %s --check-prefix=REMARK --check-prefix=PRINT 24; RUN: llvm-dis %t5.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR1 25; RUN: llvm-dis %t5.2.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR2 26 27; PRINT-DAG: Devirtualized call to {{.*}} (_ZN1A1nEi) 28 29; REMARK-DAG: single-impl: devirtualized a call to _ZN1A1nEi 30 31target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 32target triple = "x86_64-grtev4-linux-gnu" 33 34source_filename = "-" 35 36%struct.A = type { i32 (...)** } 37%struct.B = type { %struct.A } 38 39$_ZTV1B = comdat any 40 41@_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 42 43define i32 @_ZN1B1fEi(%struct.B* %this, i32 %a) #0 comdat($_ZTV1B) { 44 ret i32 0; 45} 46 47define i32 @_ZN1B1nEi(%struct.B* %this, i32 %a) #0 comdat($_ZTV1B) { 48 ret i32 0; 49} 50 51; Ensures that vtable of B is live so that we will attempt devirt. 52define dso_local i32 @use_B(%struct.B* %a) { 53entry: 54 %0 = bitcast %struct.B* %a to i32 (...)*** 55 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 56 ret i32 0 57} 58 59; CHECK-IR1: define i32 @test( 60define i32 @test(%struct.A* %obj, i32 %a) { 61entry: 62 %0 = bitcast %struct.A* %obj to i8*** 63 %vtable = load i8**, i8*** %0 64 %1 = bitcast i8** %vtable to i8* 65 %p = call i1 @llvm.type.test(i8* %1, metadata !"_ZTS1A") 66 call void @llvm.assume(i1 %p) 67 %fptrptr = getelementptr i8*, i8** %vtable, i32 1 68 %2 = bitcast i8** %fptrptr to i32 (%struct.A*, i32)** 69 %fptr1 = load i32 (%struct.A*, i32)*, i32 (%struct.A*, i32)** %2, align 8 70 71 ; Check that the call was devirtualized. 72 ; CHECK-IR1: tail call i32 {{.*}}@_ZN1A1nEi 73 %call = tail call i32 %fptr1(%struct.A* nonnull %obj, i32 %a) 74 75 ret i32 %call 76} 77 78; CHECK-IR2: define i32 @test2 79; Check that the call was devirtualized. 80; CHECK-IR2: tail call i32 @_ZN1A1nEi 81 82declare i1 @llvm.type.test(i8*, metadata) 83declare void @llvm.assume(i1) 84 85attributes #0 = { noinline optnone } 86 87!0 = !{i64 16, !"_ZTS1A"} 88!1 = !{i64 16, !"_ZTS1B"} 89