107 lines · plain
1; REQUIRES: x86-registered-target2 3;; Ensure we don't incorrectly devirtualization when one vtable contains an4;; alias (i.e. ensure analysis does not improperly ignore this implementation).5 6;; Test pure ThinLTO7 8;; Generate unsplit module with summary for ThinLTO index-based WPD.9; RUN: opt -thinlto-bc -o %t1.o %s10 11;; Check that we have properly recorded the alias in the vtable summary.12; RUN: llvm-dis -o - %t1.o | FileCheck %s --check-prefix SUMMARY13; SUMMARY: gv: (name: "_ZTV1D", {{.*}} vTableFuncs: ((virtFunc: ^[[ALIAS:([0-9]+)]], offset: 16))14; SUMMARY: ^[[ALIAS]] = gv: (name: "_ZN1D1mEiAlias"15 16; RUN: llvm-lto2 run %t1.o -save-temps -pass-remarks=. \17; RUN: -whole-program-visibility \18; RUN: -wholeprogramdevirt-print-index-based \19; RUN: -o %t2 \20; RUN: -r=%t1.o,test,px \21; RUN: -r=%t1.o,_ZTV1D,px \22; RUN: -r=%t1.o,_ZN1D1mEi,px \23; RUN: -r=%t1.o,_ZN1D1mEiAlias,px \24; RUN: -r=%t1.o,_ZTV1B,px \25; RUN: -r=%t1.o,_ZN1B1mEi,px \26; RUN: 2>&1 | FileCheck %s --implicit-check-not {{[Dd]}}evirtualized --allow-empty27; RUN: llvm-dis %t2.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR28 29;; Test hybrid Thin/Regular LTO30 31;; Generate split module with summary for hybrid Thin/Regular LTO WPD.32; RUN: opt -thinlto-bc -thinlto-split-lto-unit -o %t3.o %s33 34; RUN: llvm-lto2 run %t3.o -save-temps -pass-remarks=. \35; RUN: -whole-program-visibility \36; RUN: -o %t4 \37; RUN: -r=%t3.o,test,px \38; RUN: -r=%t3.o,_ZTV1D, \39; RUN: -r=%t3.o,_ZTV1D,px \40; RUN: -r=%t3.o,_ZN1D1mEi,px \41; RUN: -r=%t3.o,_ZN1D1mEiAlias,px \42; RUN: -r=%t3.o,_ZN1D1mEiAlias, \43; RUN: -r=%t3.o,_ZTV1B, \44; RUN: -r=%t3.o,_ZTV1B,px \45; RUN: -r=%t3.o,_ZN1B1mEi,px \46; RUN: -r=%t3.o,_ZN1B1mEi, \47; RUN: 2>&1 | FileCheck %s --implicit-check-not {{[Dd]}}evirtualized --allow-empty48; RUN: llvm-dis %t4.1.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR49 50;; Test Regular LTO51 52; RUN: opt -o %t5.o %s53; RUN: llvm-lto2 run %t5.o -save-temps -pass-remarks=. \54; RUN: -whole-program-visibility \55; RUN: -o %t6 \56; RUN: -r=%t5.o,test,px \57; RUN: -r=%t5.o,_ZTV1D,px \58; RUN: -r=%t5.o,_ZN1D1mEi,px \59; RUN: -r=%t5.o,_ZN1D1mEiAlias,px \60; RUN: -r=%t5.o,_ZTV1B,px \61; RUN: -r=%t5.o,_ZN1B1mEi,px \62; RUN: 2>&1 | FileCheck %s --implicit-check-not {{[Dd]}}evirtualized --allow-empty63; RUN: llvm-dis %t6.0.4.opt.bc -o - | FileCheck %s --check-prefix=CHECK-IR64 65target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"66target triple = "x86_64-grtev4-linux-gnu"67 68%struct.D = type { ptr }69%struct.B = type { %struct.D }70 71@_ZTV1D = constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr undef, ptr @_ZN1D1mEiAlias] }, !type !072@_ZTV1B = constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr undef, ptr @_ZN1B1mEi] }, !type !0, !type !173 74 75define i32 @_ZN1D1mEi(ptr %this, i32 %a) {76 ret i32 0;77}78 79@_ZN1D1mEiAlias = unnamed_addr alias i32 (ptr, i32), ptr @_ZN1D1mEi80 81define i32 @_ZN1B1mEi(ptr %this, i32 %a) {82 ret i32 0;83}84 85; CHECK-IR-LABEL: define i32 @test86define i32 @test(ptr %obj2, i32 %a) {87entry:88 %vtable2 = load ptr, ptr %obj289 %p2 = call i1 @llvm.type.test(ptr %vtable2, metadata !"_ZTS1D")90 call void @llvm.assume(i1 %p2)91 92 %fptr33 = load ptr, ptr %vtable2, align 893 94 ;; Confirm the call was not devirtualized.95 ;; CHECK-IR: %call4 = tail call i32 %fptr3396 %call4 = tail call i32 %fptr33(ptr nonnull %obj2, i32 %a)97 ret i32 %call498}99; CHECK-IR-LABEL: ret i32100; CHECK-IR-LABEL: }101 102declare i1 @llvm.type.test(ptr, metadata)103declare void @llvm.assume(i1)104 105!0 = !{i64 16, !"_ZTS1D"}106!1 = !{i64 16, !"_ZTS1B"}107