GlobalDCE: Convert tests to opaque pointers

The script mangled both virtual-functions-base-pointer-call.ll and
virtual-functions-derived-pointer-call.ll pretty badly, deleting the
run line and most of the block comment.

Replaced the bitcast with and addrspacecast in 2002-07-17-CastRef.ll,
based on the apparent intent of the test.

For 2003-07-01-SelfReference.ll, the script produced "call ptr ()
@getfunc" which surprisingly parses as valid.
This commit is contained in:
Matt Arsenault 2022-11-26 19:12:18 -05:00
parent 1ec71a9569
commit 8570893cfd
31 changed files with 313 additions and 353 deletions

View File

@ -5,7 +5,7 @@ define internal void @func() {
}
define void @main() {
%X = bitcast void ()* @func to i32* ; <i32*> [#uses=0]
%X = addrspacecast ptr @func to ptr addrspace(1) ; <i32*> [#uses=0]
ret void
}

View File

@ -1,7 +1,7 @@
; RUN: opt < %s -passes=globaldce
;
@X = global void ()* @func ; <void ()**> [#uses=0]
@X = global ptr @func ; <ptr> [#uses=0]
; Not dead, can be reachable via X
define internal void @func() {

View File

@ -5,14 +5,14 @@
; CHECK-NOT: foo
;; Unused, kills %foo
@b = internal global i32 ()* @foo ; <i32 ()**> [#uses=0]
@b = internal global ptr @foo ; <ptr> [#uses=0]
;; Should die when function %foo is killed
@foo.upgrd.1 = internal global i32 7 ; <i32*> [#uses=1]
@foo.upgrd.1 = internal global i32 7 ; <ptr> [#uses=1]
;; dies when %b dies.
define internal i32 @foo() {
%ret = load i32, i32* @foo.upgrd.1 ; <i32> [#uses=1]
%ret = load i32, ptr @foo.upgrd.1 ; <i32> [#uses=1]
ret i32 %ret
}

View File

@ -5,10 +5,10 @@
; CHECK-NOT: global
@t0 = internal global [4 x i8] c"foo\00" ; <[4 x i8]*> [#uses=1]
@t1 = internal global [4 x i8] c"bar\00" ; <[4 x i8]*> [#uses=1]
@s1 = internal global [1 x i8*] [ i8* getelementptr ([4 x i8], [4 x i8]* @t0, i32 0, i32 0) ] ; <[1 x i8*]*> [#uses=0]
@s2 = internal global [1 x i8*] [ i8* getelementptr ([4 x i8], [4 x i8]* @t1, i64 0, i64 0) ] ; <[1 x i8*]*> [#uses=0]
@b = internal global i32* @a ; <i32**> [#uses=0]
@a = internal global i32 7 ; <i32*> [#uses=1]
@t0 = internal global [4 x i8] c"foo\00" ; <ptr> [#uses=1]
@t1 = internal global [4 x i8] c"bar\00" ; <ptr> [#uses=1]
@s1 = internal global [1 x ptr] [ ptr @t0 ] ; <ptr> [#uses=0]
@s2 = internal global [1 x ptr] [ ptr @t1 ] ; <ptr> [#uses=0]
@b = internal global ptr @a ; <ptr> [#uses=0]
@a = internal global i32 7 ; <ptr> [#uses=1]

View File

@ -1,11 +1,11 @@
; RUN: opt < %s -passes=globaldce
;; Should die when function %foo is killed
@foo.upgrd.1 = internal global i32 7 ; <i32*> [#uses=3]
@bar = internal global [2 x { i32*, i32 }] [ { i32*, i32 } { i32* @foo.upgrd.1, i32 7 }, { i32*, i32 } { i32* @foo.upgrd.1, i32 1 } ] ; <[2 x { i32*, i32 }]*> [#uses=0]
@foo.upgrd.1 = internal global i32 7 ; <ptr> [#uses=3]
@bar = internal global [2 x { ptr, i32 }] [ { ptr, i32 } { ptr @foo.upgrd.1, i32 7 }, { ptr, i32 } { ptr @foo.upgrd.1, i32 1 } ] ; <ptr> [#uses=0]
define internal i32 @foo() {
%ret = load i32, i32* @foo.upgrd.1 ; <i32> [#uses=1]
%ret = load i32, ptr @foo.upgrd.1 ; <i32> [#uses=1]
ret i32 %ret
}

View File

@ -3,11 +3,11 @@
; CHECK-NOT: testfunc
declare i1 ()* @getfunc()
declare ptr @getfunc()
define internal i1 @testfunc() {
%F = call i1 ()* () @getfunc( ) ; <i1 ()*> [#uses=1]
%c = icmp eq i1 ()* %F, @testfunc ; <i1> [#uses=1]
%F = call ptr @getfunc() ; <ptr> [#uses=1]
%c = icmp eq ptr %F, @testfunc ; <i1> [#uses=1]
ret i1 %c
}

View File

@ -5,14 +5,14 @@
@A = global i32 0
; CHECK: @A = global i32 0
@D = internal alias i32, i32* @A
@D = internal alias i32, ptr @A
; DEAD-NOT: @D
@L1 = alias i32, i32* @A
; CHECK: @L1 = alias i32, i32* @A
@L1 = alias i32, ptr @A
; CHECK: @L1 = alias i32, ptr @A
@L2 = internal alias i32, i32* @L1
; CHECK: @L2 = internal alias i32, i32* @L1
@L2 = internal alias i32, ptr @L1
; CHECK: @L2 = internal alias i32, ptr @L1
@L3 = alias i32, i32* @L2
; CHECK: @L3 = alias i32, i32* @L2
@L3 = alias i32, ptr @L2
; CHECK: @L3 = alias i32, ptr @L2

View File

@ -1,4 +1,4 @@
; RUN: opt < %s -passes=globaldce
@A = internal alias void (), void ()* @F
@A = internal alias void (), ptr @F
define internal void @F() { ret void }

View File

@ -2,10 +2,10 @@
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
declare { i8*, i1 } @llvm.type.checked.load(i8*, i32, metadata)
declare { ptr, i1 } @llvm.type.checked.load(ptr, i32, metadata)
define internal void @foo() {
call void @bar_with_fptr_argument(i64 ptrtoint (void ()* @baz to i64))
call void @bar_with_fptr_argument(i64 ptrtoint (ptr @baz to i64))
ret void
}

View File

@ -70,22 +70,22 @@ $test10_c = comdat any
@test9_gv = linkonce_odr unnamed_addr global i32 42, comdat($test9_c)
; CHECK-NOT: @test9_gv
@test10_gv = linkonce_odr unnamed_addr global void ()* @test10_f, comdat($test10_c)
@test10_gv = linkonce_odr unnamed_addr global ptr @test10_f, comdat($test10_c)
; CHECK-NOT: @test10_gv
@test3_a = linkonce_odr unnamed_addr alias void (), void ()* @test3_f
@test3_a = linkonce_odr unnamed_addr alias void (), ptr @test3_f
; CHECK: @test3_a = linkonce_odr unnamed_addr alias
@test4_a = linkonce_odr unnamed_addr alias void (), void ()* @test4_f
@test4_a = linkonce_odr unnamed_addr alias void (), ptr @test4_f
; CHECK: @test4_a = linkonce_odr unnamed_addr alias
@test10_a = linkonce_odr unnamed_addr alias void (), void ()* @test10_g
@test10_a = linkonce_odr unnamed_addr alias void (), ptr @test10_g
; CHECK-NOT: @test10_a
@test5_if = linkonce_odr ifunc void (), void ()* ()* @test5_f
@test5_if = linkonce_odr ifunc void (), ptr @test5_f
; CHECK-NOT: @test5_if
@test6_if = linkonce_odr ifunc void (), void ()* ()* @test6_f
@test6_if = linkonce_odr ifunc void (), ptr @test6_f
; CHECK: @test6_if = linkonce_odr ifunc
; This function is directly used and so cannot be eliminated.
@ -123,16 +123,16 @@ entry:
declare void @test_external()
define linkonce_odr void ()* @test5_f() comdat($test5_c) {
; CHECK: define linkonce_odr void ()* @test5_f()
define linkonce_odr ptr @test5_f() comdat($test5_c) {
; CHECK: define linkonce_odr ptr @test5_f()
entry:
ret void ()* @test_external
ret ptr @test_external
}
define linkonce_odr void ()* @test6_f() comdat($test6_c) {
; CHECK: define linkonce_odr void ()* @test6_f()
define linkonce_odr ptr @test6_f() comdat($test6_c) {
; CHECK: define linkonce_odr ptr @test6_f()
entry:
ret void ()* @test_external
ret ptr @test_external
}
define linkonce_odr void @test7_f() comdat($test7_c) {
@ -150,7 +150,7 @@ entry:
define linkonce_odr void @test10_f() comdat($test10_c) {
; CHECK-NOT: @test10_f
entry:
%gv = load void ()*, void ()** @test10_gv
%gv = load ptr, ptr @test10_gv
call void @test10_a()
ret void
}
@ -167,12 +167,12 @@ entry:
; eliminated.
define void @external_user() {
call void @test1_used()
%gv = load i32, i32* @test2_used
%gv = load i32, ptr @test2_used
call void @test3_f()
call void @test4_a()
%fptr = call void() *@test5_f()
%fptr = call ptr @test5_f()
call void @test6_if()
ret void
}

View File

@ -14,19 +14,19 @@
define void @zot12() {
bb:
store i32 0, i32* @global5, align 4
store i32 0, i32* @global6, align 4
store i32 0, ptr @global5, align 4
store i32 0, ptr @global6, align 4
br label %bb2
bb1: ; preds = %bb11
%tmp = load i32, i32* @global5, align 4
%tmp = load i32, ptr @global5, align 4
br label %bb2
bb2: ; preds = %bb1, %bb
%tmp3 = phi i32 [ %tmp, %bb1 ], [ 0, %bb ]
%tmp4 = xor i32 %tmp3, zext (i1 icmp ne (i64 ptrtoint (i32* @global5 to i64), i64 1) to i32)
store i32 %tmp4, i32* @global5, align 4
%tmp5 = icmp eq i32 %tmp3, zext (i1 icmp ne (i64 ptrtoint (i32* @global5 to i64), i64 1) to i32)
%tmp4 = xor i32 %tmp3, zext (i1 icmp ne (i64 ptrtoint (ptr @global5 to i64), i64 1) to i32)
store i32 %tmp4, ptr @global5, align 4
%tmp5 = icmp eq i32 %tmp3, zext (i1 icmp ne (i64 ptrtoint (ptr @global5 to i64), i64 1) to i32)
br i1 %tmp5, label %bb8, label %bb6
bb6: ; preds = %bb2
@ -34,14 +34,14 @@ bb6: ; preds = %bb2
br label %bb8
bb8: ; preds = %bb6, %bb2
%tmp9 = load i32, i32* @global7, align 4
%tmp9 = load i32, ptr @global7, align 4
%tmp10 = icmp eq i32 %tmp9, 0
br i1 %tmp10, label %bb11, label %bb15
bb11: ; preds = %bb8
%tmp12 = load i32, i32* @global6, align 4
%tmp12 = load i32, ptr @global6, align 4
%tmp13 = add nsw i32 %tmp12, 1
store i32 %tmp13, i32* @global6, align 4
store i32 %tmp13, ptr @global6, align 4
%tmp14 = icmp slt i32 %tmp13, 42
br i1 %tmp14, label %bb1, label %bb15
@ -51,7 +51,7 @@ bb15: ; preds = %bb11, %bb8
define i32 @quux13() {
bb:
store i32 1, i32* @global5, align 4
store i32 1, ptr @global5, align 4
ret i32 1
}
@ -69,9 +69,9 @@ bb:
define void @blam() {
bb:
store i32 ptrtoint (i32* @global to i32), i32* getelementptr inbounds (%struct.ham, %struct.ham* @global8, i64 0, i32 0), align 4
store i32 0, i32* @global9, align 4
%tmp = load i32, i32* getelementptr inbounds (%struct.ham, %struct.ham* @global8, i64 0, i32 0), align 4
store i32 ptrtoint (ptr @global to i32), ptr @global8, align 4
store i32 0, ptr @global9, align 4
%tmp = load i32, ptr @global8, align 4
br label %bb1
bb1: ; preds = %bb1, %bb
@ -89,9 +89,9 @@ bb1: ; preds = %bb1, %bb
br i1 %tmp12, label %bb13, label %bb1
bb13: ; preds = %bb1
store i32 %tmp10, i32* getelementptr inbounds (%struct.ham, %struct.ham* @global8, i64 0, i32 0), align 4
store i32 0, i32* @global10, align 4
store i32 %tmp6, i32* @global11, align 4
store i32 20, i32* @global9, align 4
store i32 %tmp10, ptr @global8, align 4
store i32 0, ptr @global10, align 4
store i32 %tmp6, ptr @global11, align 4
store i32 20, ptr @global9, align 4
ret void
}

View File

@ -3,7 +3,7 @@
; Tests whether globaldce does the right cleanup while removing @bar
; so that a dead BlockAddress reference to foo won't prevent other passes
; to work properly, e.g. simplifycfg
@bar = internal unnamed_addr constant i8* blockaddress(@foo, %L1)
@bar = internal unnamed_addr constant ptr blockaddress(@foo, %L1)
; CHECK-LABEL: foo
; CHECK-NOT: br label %L1

View File

@ -6,7 +6,7 @@
; test_global2 is a normal global using an available externally function.
; CHECK: @test_global2 =
@test_global2 = global i32 ()* @test_function2
@test_global2 = global ptr @test_function2
; test_function should not be emitted to the .s file.
; CHECK-NOT: define {{.*}} @test_function()

View File

@ -2,12 +2,12 @@
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
@if = ifunc void (), void ()* ()* @fn
@if = ifunc void (), ptr @fn
define internal void ()* @fn() {
define internal ptr @fn() {
entry:
ret void ()* null
ret ptr null
}
; CHECK-DAG: @if = ifunc void (), void ()* ()* @fn
; CHECK-DAG: define internal void ()* @fn(
; CHECK-DAG: @if = ifunc void (), ptr @fn
; CHECK-DAG: define internal ptr @fn(

View File

@ -1,12 +1,12 @@
; RUN: opt -S -passes=globaldce < %s | FileCheck %s
; Test that the presence of debug intrinsics isn't affecting GlobalDCE.
; CHECK: @llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_notremovable, i8* null }]
; CHECK: @llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @_notremovable, ptr null }]
; CHECK-NOT: @_GLOBAL__I_a
declare void @_notremovable()
@llvm.global_ctors = appending global [3 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I_a, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I_b, i8* null }, { i32, void ()*, i8* } { i32 65535, void ()* @_notremovable, i8* null }]
@llvm.global_ctors = appending global [3 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @_GLOBAL__I_a, ptr null }, { i32, ptr, ptr } { i32 65535, ptr @_GLOBAL__I_b, ptr null }, { i32, ptr, ptr } { i32 65535, ptr @_notremovable, ptr null }]
@x = internal unnamed_addr constant i8 undef, align 1
@ -19,7 +19,7 @@ entry:
; Function Attrs: nounwind readnone
define internal void @_GLOBAL__I_b() #1 section "__TEXT,__StaticInit,regular,pure_instructions" {
entry:
tail call void @llvm.dbg.value(metadata i8* @x, metadata !4, metadata !DIExpression(DW_OP_deref, DW_OP_constu, 0, DW_OP_swap, DW_OP_xderef)), !dbg !5
tail call void @llvm.dbg.value(metadata ptr @x, metadata !4, metadata !DIExpression(DW_OP_deref, DW_OP_constu, 0, DW_OP_swap, DW_OP_xderef)), !dbg !5
ret void
}

View File

@ -9,33 +9,33 @@
@foo = global %class.Foo zeroinitializer, align 4
@_ZN3Bar18LINKER_INITIALIZEDE = external constant i32
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__I_a, i8* null }]
@llvm.global_ctors = appending global [1 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @_GLOBAL__I_a, ptr null }]
define internal void @__cxx_global_var_init() section "__TEXT,__StaticInit,regular,pure_instructions" {
%1 = load i32, i32* @_ZN3Bar18LINKER_INITIALIZEDE, align 4
call void @_ZN3FooC1E17LinkerInitialized(%class.Foo* @foo, i32 %1)
%1 = load i32, ptr @_ZN3Bar18LINKER_INITIALIZEDE, align 4
call void @_ZN3FooC1E17LinkerInitialized(ptr @foo, i32 %1)
ret void
}
; Function Attrs: ssp uwtable
define linkonce_odr void @_ZN3FooC1E17LinkerInitialized(%class.Foo* %this, i32) unnamed_addr #0 align 2 {
%2 = alloca %class.Foo*, align 8
define linkonce_odr void @_ZN3FooC1E17LinkerInitialized(ptr %this, i32) unnamed_addr #0 align 2 {
%2 = alloca ptr, align 8
%3 = alloca i32, align 4
store %class.Foo* %this, %class.Foo** %2, align 8
store i32 %0, i32* %3, align 4
%4 = load %class.Foo*, %class.Foo** %2
%5 = load i32, i32* %3, align 4
call void @_ZN3FooC2E17LinkerInitialized(%class.Foo* %4, i32 %5)
store ptr %this, ptr %2, align 8
store i32 %0, ptr %3, align 4
%4 = load ptr, ptr %2
%5 = load i32, ptr %3, align 4
call void @_ZN3FooC2E17LinkerInitialized(ptr %4, i32 %5)
ret void
}
; Function Attrs: nounwind ssp uwtable
define linkonce_odr void @_ZN3FooC2E17LinkerInitialized(%class.Foo* %this, i32) unnamed_addr #1 align 2 {
%2 = alloca %class.Foo*, align 8
define linkonce_odr void @_ZN3FooC2E17LinkerInitialized(ptr %this, i32) unnamed_addr #1 align 2 {
%2 = alloca ptr, align 8
%3 = alloca i32, align 4
store %class.Foo* %this, %class.Foo** %2, align 8
store i32 %0, i32* %3, align 4
%4 = load %class.Foo*, %class.Foo** %2
store ptr %this, ptr %2, align 8
store i32 %0, ptr %3, align 4
%4 = load ptr, ptr %2
ret void
}

View File

@ -1,6 +1,6 @@
; RUN: opt -S -passes=globaldce < %s | FileCheck %s
@L = internal unnamed_addr constant [3 x i8*] [i8* blockaddress(@test1, %L1), i8* blockaddress(@test1, %L2), i8* null], align 16
@L = internal unnamed_addr constant [3 x ptr] [ptr blockaddress(@test1, %L1), ptr blockaddress(@test1, %L2), ptr null], align 16
; CHECK: @L = internal unnamed_addr constant
@ -9,9 +9,9 @@ entry:
br label %L1
L1:
%arrayidx = getelementptr inbounds [3 x i8*], [3 x i8*]* @L, i32 0, i32 %idx
%l = load i8*, i8** %arrayidx
indirectbr i8* %l, [label %L1, label %L2]
%arrayidx = getelementptr inbounds [3 x ptr], ptr @L, i32 0, i32 %idx
%l = load ptr, ptr %arrayidx
indirectbr ptr %l, [label %L1, label %L2]
L2:
ret void

View File

@ -22,53 +22,49 @@ target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
; The virtual call in test could be dispatched to either A::foo or B::foo, so
; both must be retained.
%struct.A = type { i32 (...)** }
%struct.A = type { ptr }
%struct.B = type { %struct.A }
; CHECK: @_ZTV1A = internal unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* null, i8* bitcast (i32 (%struct.A*)* @_ZN1A3fooEv to i8*)] }
@_ZTV1A = internal unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* null, i8* bitcast (i32 (%struct.A*)* @_ZN1A3fooEv to i8*)] }, align 8, !type !0, !type !1, !vcall_visibility !2
; CHECK: @_ZTV1A = internal unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr null, ptr @_ZN1A3fooEv] }
@_ZTV1A = internal unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr null, ptr @_ZN1A3fooEv] }, align 8, !type !0, !type !1, !vcall_visibility !2
; CHECK: @_ZTV1B = internal unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* null, i8* bitcast (i32 (%struct.B*)* @_ZN1B3fooEv to i8*)] }
@_ZTV1B = internal unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* null, i8* bitcast (i32 (%struct.B*)* @_ZN1B3fooEv to i8*)] }, align 8, !type !0, !type !1, !type !3, !type !4, !vcall_visibility !2
; CHECK: @_ZTV1B = internal unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr null, ptr @_ZN1B3fooEv] }
@_ZTV1B = internal unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr null, ptr @_ZN1B3fooEv] }, align 8, !type !0, !type !1, !type !3, !type !4, !vcall_visibility !2
; CHECK: define internal i32 @_ZN1A3fooEv(
define internal i32 @_ZN1A3fooEv(%struct.A* nocapture readnone %this) {
define internal i32 @_ZN1A3fooEv(ptr nocapture readnone %this) {
entry:
ret i32 42
}
; CHECK: define internal i32 @_ZN1B3fooEv(
define internal i32 @_ZN1B3fooEv(%struct.B* nocapture readnone %this) {
define internal i32 @_ZN1B3fooEv(ptr nocapture readnone %this) {
entry:
ret i32 1337
}
define hidden void @_ZN1AC2Ev(%struct.A* nocapture %this) {
define hidden void @_ZN1AC2Ev(ptr nocapture %this) {
entry:
%0 = getelementptr inbounds %struct.A, %struct.A* %this, i64 0, i32 0
store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTV1A, i64 0, inrange i32 0, i64 2) to i32 (...)**), i32 (...)*** %0, align 8
store ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTV1A, i64 0, inrange i32 0, i64 2), ptr %this, align 8
ret void
}
define hidden void @_ZN1BC2Ev(%struct.B* nocapture %this) {
define hidden void @_ZN1BC2Ev(ptr nocapture %this) {
entry:
%0 = getelementptr inbounds %struct.B, %struct.B* %this, i64 0, i32 0, i32 0
store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTV1B, i64 0, inrange i32 0, i64 2) to i32 (...)**), i32 (...)*** %0, align 8
store ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTV1B, i64 0, inrange i32 0, i64 2), ptr %this, align 8
ret void
}
define hidden i32 @test(%struct.A* %p) {
define hidden i32 @test(ptr %p) {
entry:
%0 = bitcast %struct.A* %p to i8**
%vtable1 = load i8*, i8** %0, align 8
%1 = tail call { i8*, i1 } @llvm.type.checked.load(i8* %vtable1, i32 0, metadata !"_ZTS1A"), !nosanitize !10
%2 = extractvalue { i8*, i1 } %1, 0, !nosanitize !10
%3 = bitcast i8* %2 to i32 (%struct.A*)*, !nosanitize !10
%call = tail call i32 %3(%struct.A* %p)
%vtable1 = load ptr, ptr %p, align 8
%0 = tail call { ptr, i1 } @llvm.type.checked.load(ptr %vtable1, i32 0, metadata !"_ZTS1A"), !nosanitize !10
%1 = extractvalue { ptr, i1 } %0, 0, !nosanitize !10
%call = tail call i32 %1(ptr %p)
ret i32 %call
}
declare { i8*, i1 } @llvm.type.checked.load(i8*, i32, metadata) #2
declare { ptr, i1 } @llvm.type.checked.load(ptr, i32, metadata) #2
!llvm.module.flags = !{!5}

View File

@ -29,84 +29,78 @@ target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
; or B::foo. It can't be dispatched to A::bar or B::bar as the function pointer
; does not match, so those can be removed.
%struct.A = type { i32 (...)** }
%struct.A = type { ptr }
%struct.B = type { %struct.A }
; CHECK: @_ZTV1A = internal unnamed_addr constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* null, i8* bitcast (i32 (%struct.A*, i32)* @_ZN1A3fooEi to i8*), i8* null] }
@_ZTV1A = internal unnamed_addr constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* null, i8* bitcast (i32 (%struct.A*, i32)* @_ZN1A3fooEi to i8*), i8* bitcast (i32 (%struct.A*, float)* @_ZN1A3barEf to i8*)] }, align 8, !type !0, !type !1, !type !2, !vcall_visibility !3
; CHECK: @_ZTV1B = internal unnamed_addr constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* null, i8* bitcast (i32 (%struct.B*, i32)* @_ZN1B3fooEi to i8*), i8* null] }
@_ZTV1B = internal unnamed_addr constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* null, i8* bitcast (i32 (%struct.B*, i32)* @_ZN1B3fooEi to i8*), i8* bitcast (i32 (%struct.B*, float)* @_ZN1B3barEf to i8*)] }, align 8, !type !0, !type !1, !type !2, !type !4, !type !5, !type !6, !vcall_visibility !3
; CHECK: @_ZTV1A = internal unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr null, ptr @_ZN1A3fooEi, ptr null] }
@_ZTV1A = internal unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr null, ptr @_ZN1A3fooEi, ptr @_ZN1A3barEf] }, align 8, !type !0, !type !1, !type !2, !vcall_visibility !3
; CHECK: @_ZTV1B = internal unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr null, ptr @_ZN1B3fooEi, ptr null] }
@_ZTV1B = internal unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr null, ptr @_ZN1B3fooEi, ptr @_ZN1B3barEf] }, align 8, !type !0, !type !1, !type !2, !type !4, !type !5, !type !6, !vcall_visibility !3
; CHECK: define internal i32 @_ZN1A3fooEi(
define internal i32 @_ZN1A3fooEi(%struct.A* nocapture readnone %this, i32) unnamed_addr #1 align 2 {
define internal i32 @_ZN1A3fooEi(ptr nocapture readnone %this, i32) unnamed_addr #1 align 2 {
entry:
ret i32 1
}
; CHECK-NOT: define internal i32 @_ZN1A3barEf(
define internal i32 @_ZN1A3barEf(%struct.A* nocapture readnone %this, float) unnamed_addr #1 align 2 {
define internal i32 @_ZN1A3barEf(ptr nocapture readnone %this, float) unnamed_addr #1 align 2 {
entry:
ret i32 2
}
; CHECK: define internal i32 @_ZN1B3fooEi(
define internal i32 @_ZN1B3fooEi(%struct.B* nocapture readnone %this, i32) unnamed_addr #1 align 2 {
define internal i32 @_ZN1B3fooEi(ptr nocapture readnone %this, i32) unnamed_addr #1 align 2 {
entry:
ret i32 3
}
; CHECK-NOT: define internal i32 @_ZN1B3barEf(
define internal i32 @_ZN1B3barEf(%struct.B* nocapture readnone %this, float) unnamed_addr #1 align 2 {
define internal i32 @_ZN1B3barEf(ptr nocapture readnone %this, float) unnamed_addr #1 align 2 {
entry:
ret i32 4
}
define hidden void @_ZN1AC2Ev(%struct.A* nocapture %this) {
define hidden void @_ZN1AC2Ev(ptr nocapture %this) {
entry:
%0 = getelementptr inbounds %struct.A, %struct.A* %this, i64 0, i32 0
store i32 (...)** bitcast (i8** getelementptr inbounds ({ [4 x i8*] }, { [4 x i8*] }* @_ZTV1A, i64 0, inrange i32 0, i64 2) to i32 (...)**), i32 (...)*** %0, align 8
store ptr getelementptr inbounds ({ [4 x ptr] }, ptr @_ZTV1A, i64 0, inrange i32 0, i64 2), ptr %this, align 8
ret void
}
define hidden void @_ZN1BC2Ev(%struct.B* nocapture %this) {
define hidden void @_ZN1BC2Ev(ptr nocapture %this) {
entry:
%0 = getelementptr inbounds %struct.B, %struct.B* %this, i64 0, i32 0, i32 0
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
store ptr getelementptr inbounds ({ [4 x ptr] }, ptr @_ZTV1B, i64 0, inrange i32 0, i64 2), ptr %this, align 8
ret void
}
define hidden i32 @test(%struct.A* %p, i64 %q.coerce0, i64 %q.coerce1) {
define hidden i32 @test(ptr %p, i64 %q.coerce0, i64 %q.coerce1) {
entry:
%0 = bitcast %struct.A* %p to i8*
%1 = getelementptr inbounds i8, i8* %0, i64 %q.coerce1
%this.adjusted = bitcast i8* %1 to %struct.A*
%2 = and i64 %q.coerce0, 1
%memptr.isvirtual = icmp eq i64 %2, 0
%0 = getelementptr inbounds i8, ptr %p, i64 %q.coerce1
%1 = and i64 %q.coerce0, 1
%memptr.isvirtual = icmp eq i64 %1, 0
br i1 %memptr.isvirtual, label %memptr.nonvirtual, label %memptr.virtual
memptr.virtual: ; preds = %entry
%3 = bitcast i8* %1 to i8**
%vtable = load i8*, i8** %3, align 8
%4 = add i64 %q.coerce0, -1
%5 = getelementptr i8, i8* %vtable, i64 %4, !nosanitize !12
%6 = tail call { i8*, i1 } @llvm.type.checked.load(i8* %5, i32 0, metadata !"_ZTSM1AFiiE.virtual"), !nosanitize !12
%7 = extractvalue { i8*, i1 } %6, 0, !nosanitize !12
%memptr.virtualfn = bitcast i8* %7 to i32 (%struct.A*, i32)*, !nosanitize !12
%vtable = load ptr, ptr %0, align 8
%2 = add i64 %q.coerce0, -1
%3 = getelementptr i8, ptr %vtable, i64 %2, !nosanitize !12
%4 = tail call { ptr, i1 } @llvm.type.checked.load(ptr %3, i32 0, metadata !"_ZTSM1AFiiE.virtual"), !nosanitize !12
%5 = extractvalue { ptr, i1 } %4, 0, !nosanitize !12
br label %memptr.end
memptr.nonvirtual: ; preds = %entry
%memptr.nonvirtualfn = inttoptr i64 %q.coerce0 to i32 (%struct.A*, i32)*
%memptr.nonvirtualfn = inttoptr i64 %q.coerce0 to ptr
br label %memptr.end
memptr.end: ; preds = %memptr.nonvirtual, %memptr.virtual
%8 = phi i32 (%struct.A*, i32)* [ %memptr.virtualfn, %memptr.virtual ], [ %memptr.nonvirtualfn, %memptr.nonvirtual ]
%call = tail call i32 %8(%struct.A* %this.adjusted, i32 42)
%6 = phi ptr [ %5, %memptr.virtual ], [ %memptr.nonvirtualfn, %memptr.nonvirtual ]
%call = tail call i32 %6(ptr %0, i32 42)
ret i32 %call
}
declare { i8*, i1 } @llvm.type.checked.load(i8*, i32, metadata)
declare { ptr, i1 } @llvm.type.checked.load(ptr, i32, metadata)
!llvm.module.flags = !{!7}

View File

@ -22,53 +22,49 @@ target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
; The virtual call in test can only be dispatched to B::foo (or a more-derived
; class, if there was one), so A::foo can be removed.
%struct.A = type { i32 (...)** }
%struct.A = type { ptr }
%struct.B = type { %struct.A }
; CHECK: @_ZTV1A = internal unnamed_addr constant { [3 x i8*] } zeroinitializer
@_ZTV1A = internal unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* null, i8* bitcast (i32 (%struct.A*)* @_ZN1A3fooEv to i8*)] }, align 8, !type !0, !type !1, !vcall_visibility !2
; CHECK: @_ZTV1A = internal unnamed_addr constant { [3 x ptr] } zeroinitializer
@_ZTV1A = internal unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr null, ptr @_ZN1A3fooEv] }, align 8, !type !0, !type !1, !vcall_visibility !2
; CHECK: @_ZTV1B = internal unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* null, i8* bitcast (i32 (%struct.B*)* @_ZN1B3fooEv to i8*)] }
@_ZTV1B = internal unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* null, i8* bitcast (i32 (%struct.B*)* @_ZN1B3fooEv to i8*)] }, align 8, !type !0, !type !1, !type !3, !type !4, !vcall_visibility !2
; CHECK: @_ZTV1B = internal unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr null, ptr @_ZN1B3fooEv] }
@_ZTV1B = internal unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr null, ptr @_ZN1B3fooEv] }, align 8, !type !0, !type !1, !type !3, !type !4, !vcall_visibility !2
; CHECK-NOT: define internal i32 @_ZN1A3fooEv(
define internal i32 @_ZN1A3fooEv(%struct.A* nocapture readnone %this) {
define internal i32 @_ZN1A3fooEv(ptr nocapture readnone %this) {
entry:
ret i32 42
}
; CHECK: define internal i32 @_ZN1B3fooEv(
define internal i32 @_ZN1B3fooEv(%struct.B* nocapture readnone %this) {
define internal i32 @_ZN1B3fooEv(ptr nocapture readnone %this) {
entry:
ret i32 1337
}
define hidden void @_ZN1AC2Ev(%struct.A* nocapture %this) {
define hidden void @_ZN1AC2Ev(ptr nocapture %this) {
entry:
%0 = getelementptr inbounds %struct.A, %struct.A* %this, i64 0, i32 0
store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTV1A, i64 0, inrange i32 0, i64 2) to i32 (...)**), i32 (...)*** %0, align 8
store ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTV1A, i64 0, inrange i32 0, i64 2), ptr %this, align 8
ret void
}
define hidden void @_ZN1BC2Ev(%struct.B* nocapture %this) {
define hidden void @_ZN1BC2Ev(ptr nocapture %this) {
entry:
%0 = getelementptr inbounds %struct.B, %struct.B* %this, i64 0, i32 0, i32 0
store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTV1B, i64 0, inrange i32 0, i64 2) to i32 (...)**), i32 (...)*** %0, align 8
store ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTV1B, i64 0, inrange i32 0, i64 2), ptr %this, align 8
ret void
}
define hidden i32 @test(%struct.B* %p) {
define hidden i32 @test(ptr %p) {
entry:
%0 = bitcast %struct.B* %p to i8**
%vtable1 = load i8*, i8** %0, align 8
%1 = tail call { i8*, i1 } @llvm.type.checked.load(i8* %vtable1, i32 0, metadata !"_ZTS1B"), !nosanitize !10
%2 = extractvalue { i8*, i1 } %1, 0, !nosanitize !10
%3 = bitcast i8* %2 to i32 (%struct.B*)*, !nosanitize !10
%call = tail call i32 %3(%struct.B* %p)
%vtable1 = load ptr, ptr %p, align 8
%0 = tail call { ptr, i1 } @llvm.type.checked.load(ptr %vtable1, i32 0, metadata !"_ZTS1B"), !nosanitize !10
%1 = extractvalue { ptr, i1 } %0, 0, !nosanitize !10
%call = tail call i32 %1(ptr %p)
ret i32 %call
}
declare { i8*, i1 } @llvm.type.checked.load(i8*, i32, metadata) #2
declare { ptr, i1 } @llvm.type.checked.load(ptr, i32, metadata) #2
!llvm.module.flags = !{!5}

View File

@ -31,84 +31,78 @@ target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
; does not match, and it can't be dispatched to A::foo as the object type
; doesn't match, so those can be removed.
%struct.A = type { i32 (...)** }
%struct.A = type { ptr }
%struct.B = type { %struct.A }
; CHECK: @_ZTV1A = internal unnamed_addr constant { [4 x i8*] } zeroinitializer
@_ZTV1A = internal unnamed_addr constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* null, i8* bitcast (i32 (%struct.A*, i32)* @_ZN1A3fooEi to i8*), i8* bitcast (i32 (%struct.A*, float)* @_ZN1A3barEf to i8*)] }, align 8, !type !0, !type !1, !type !2, !vcall_visibility !3
; CHECK: @_ZTV1B = internal unnamed_addr constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* null, i8* bitcast (i32 (%struct.B*, i32)* @_ZN1B3fooEi to i8*), i8* null] }
@_ZTV1B = internal unnamed_addr constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* null, i8* bitcast (i32 (%struct.B*, i32)* @_ZN1B3fooEi to i8*), i8* bitcast (i32 (%struct.B*, float)* @_ZN1B3barEf to i8*)] }, align 8, !type !0, !type !1, !type !2, !type !4, !type !5, !type !6, !vcall_visibility !3
; CHECK: @_ZTV1A = internal unnamed_addr constant { [4 x ptr] } zeroinitializer
@_ZTV1A = internal unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr null, ptr @_ZN1A3fooEi, ptr @_ZN1A3barEf] }, align 8, !type !0, !type !1, !type !2, !vcall_visibility !3
; CHECK: @_ZTV1B = internal unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr null, ptr @_ZN1B3fooEi, ptr null] }
@_ZTV1B = internal unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr null, ptr @_ZN1B3fooEi, ptr @_ZN1B3barEf] }, align 8, !type !0, !type !1, !type !2, !type !4, !type !5, !type !6, !vcall_visibility !3
; CHECK-NOT: define internal i32 @_ZN1A3fooEi(
define internal i32 @_ZN1A3fooEi(%struct.A* nocapture readnone %this, i32) unnamed_addr #1 align 2 {
define internal i32 @_ZN1A3fooEi(ptr nocapture readnone %this, i32) unnamed_addr #1 align 2 {
entry:
ret i32 1
}
; CHECK-NOT: define internal i32 @_ZN1A3barEf(
define internal i32 @_ZN1A3barEf(%struct.A* nocapture readnone %this, float) unnamed_addr #1 align 2 {
define internal i32 @_ZN1A3barEf(ptr nocapture readnone %this, float) unnamed_addr #1 align 2 {
entry:
ret i32 2
}
; CHECK: define internal i32 @_ZN1B3fooEi(
define internal i32 @_ZN1B3fooEi(%struct.B* nocapture readnone %this, i32) unnamed_addr #1 align 2 {
define internal i32 @_ZN1B3fooEi(ptr nocapture readnone %this, i32) unnamed_addr #1 align 2 {
entry:
ret i32 3
}
; CHECK-NOT: define internal i32 @_ZN1B3barEf(
define internal i32 @_ZN1B3barEf(%struct.B* nocapture readnone %this, float) unnamed_addr #1 align 2 {
define internal i32 @_ZN1B3barEf(ptr nocapture readnone %this, float) unnamed_addr #1 align 2 {
entry:
ret i32 4
}
define hidden void @_ZN1AC2Ev(%struct.A* nocapture %this) {
define hidden void @_ZN1AC2Ev(ptr nocapture %this) {
entry:
%0 = getelementptr inbounds %struct.A, %struct.A* %this, i64 0, i32 0
store i32 (...)** bitcast (i8** getelementptr inbounds ({ [4 x i8*] }, { [4 x i8*] }* @_ZTV1A, i64 0, inrange i32 0, i64 2) to i32 (...)**), i32 (...)*** %0, align 8
store ptr getelementptr inbounds ({ [4 x ptr] }, ptr @_ZTV1A, i64 0, inrange i32 0, i64 2), ptr %this, align 8
ret void
}
define hidden void @_ZN1BC2Ev(%struct.B* nocapture %this) {
define hidden void @_ZN1BC2Ev(ptr nocapture %this) {
entry:
%0 = getelementptr inbounds %struct.B, %struct.B* %this, i64 0, i32 0, i32 0
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
store ptr getelementptr inbounds ({ [4 x ptr] }, ptr @_ZTV1B, i64 0, inrange i32 0, i64 2), ptr %this, align 8
ret void
}
define hidden i32 @test(%struct.B* %p, i64 %q.coerce0, i64 %q.coerce1) {
define hidden i32 @test(ptr %p, i64 %q.coerce0, i64 %q.coerce1) {
entry:
%0 = bitcast %struct.B* %p to i8*
%1 = getelementptr inbounds i8, i8* %0, i64 %q.coerce1
%this.adjusted = bitcast i8* %1 to %struct.B*
%2 = and i64 %q.coerce0, 1
%memptr.isvirtual = icmp eq i64 %2, 0
%0 = getelementptr inbounds i8, ptr %p, i64 %q.coerce1
%1 = and i64 %q.coerce0, 1
%memptr.isvirtual = icmp eq i64 %1, 0
br i1 %memptr.isvirtual, label %memptr.nonvirtual, label %memptr.virtual
memptr.virtual: ; preds = %entry
%3 = bitcast i8* %1 to i8**
%vtable = load i8*, i8** %3, align 8
%4 = add i64 %q.coerce0, -1
%5 = getelementptr i8, i8* %vtable, i64 %4, !nosanitize !12
%6 = tail call { i8*, i1 } @llvm.type.checked.load(i8* %5, i32 0, metadata !"_ZTSM1BFiiE.virtual"), !nosanitize !12
%7 = extractvalue { i8*, i1 } %6, 0, !nosanitize !12
%memptr.virtualfn = bitcast i8* %7 to i32 (%struct.B*, i32)*, !nosanitize !12
%vtable = load ptr, ptr %0, align 8
%2 = add i64 %q.coerce0, -1
%3 = getelementptr i8, ptr %vtable, i64 %2, !nosanitize !12
%4 = tail call { ptr, i1 } @llvm.type.checked.load(ptr %3, i32 0, metadata !"_ZTSM1BFiiE.virtual"), !nosanitize !12
%5 = extractvalue { ptr, i1 } %4, 0, !nosanitize !12
br label %memptr.end
memptr.nonvirtual: ; preds = %entry
%memptr.nonvirtualfn = inttoptr i64 %q.coerce0 to i32 (%struct.B*, i32)*
%memptr.nonvirtualfn = inttoptr i64 %q.coerce0 to ptr
br label %memptr.end
memptr.end: ; preds = %memptr.nonvirtual, %memptr.virtual
%8 = phi i32 (%struct.B*, i32)* [ %memptr.virtualfn, %memptr.virtual ], [ %memptr.nonvirtualfn, %memptr.nonvirtual ]
%call = tail call i32 %8(%struct.B* %this.adjusted, i32 42)
%6 = phi ptr [ %5, %memptr.virtual ], [ %memptr.nonvirtualfn, %memptr.nonvirtual ]
%call = tail call i32 %6(ptr %0, i32 42)
ret i32 %call
}
declare { i8*, i1 } @llvm.type.checked.load(i8*, i32, metadata)
declare { ptr, i1 } @llvm.type.checked.load(ptr, i32, metadata)
!llvm.module.flags = !{!7}

View File

@ -2,26 +2,26 @@
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
declare { i8*, i1 } @llvm.type.checked.load(i8*, i32, metadata)
declare { ptr, i1 } @llvm.type.checked.load(ptr, i32, metadata)
@vtableA = internal unnamed_addr constant { [2 x i32] } { [2 x i32] [
i32 0,
i32 trunc (i64 sub (i64 ptrtoint (void ()* @vfunc2 to i64), i64 ptrtoint ({ [2 x i32] }* @vtableA to i64)) to i32)
i32 trunc (i64 sub (i64 ptrtoint (ptr @vfunc2 to i64), i64 ptrtoint (ptr @vtableA to i64)) to i32)
]}, align 8, !type !{i64 0, !"vfunc1.type"}, !type !{i64 4, !"vfunc2.type"}, !vcall_visibility !{i64 2}
; CHECK: @vtableA = internal unnamed_addr constant { [2 x i32] } { [2 x i32] [
; CHECK-SAME: i32 0,
; CHECK-SAME: i32 trunc (i64 sub (i64 ptrtoint (void ()* @vfunc2 to i64), i64 ptrtoint ({ [2 x i32] }* @vtableA to i64)) to i32)
; CHECK-SAME: i32 trunc (i64 sub (i64 ptrtoint (ptr @vfunc2 to i64), i64 ptrtoint (ptr @vtableA to i64)) to i32)
; CHECK-SAME: ] }, align 8
@vtableB = internal unnamed_addr constant { [2 x i32] } { [2 x i32] [
i32 trunc (i64 sub (i64 ptrtoint (void ()* @vfunc1 to i64), i64 ptrtoint ({ [2 x i32] }* @vtableB to i64)) to i32),
i32 trunc (i64 sub (i64 ptrtoint (void ()* @vfunc2 to i64), i64 ptrtoint ({ [2 x i32] }* @vtableB to i64)) to i32)
i32 trunc (i64 sub (i64 ptrtoint (ptr @vfunc1 to i64), i64 ptrtoint (ptr @vtableB to i64)) to i32),
i32 trunc (i64 sub (i64 ptrtoint (ptr @vfunc2 to i64), i64 ptrtoint (ptr @vtableB to i64)) to i32)
]}, align 8, !type !{i64 0, !"vfunc1.type"}, !type !{i64 4, !"vfunc2.type"}, !vcall_visibility !{i64 2}
; CHECK: @vtableB = internal unnamed_addr constant { [2 x i32] } { [2 x i32] [
; CHECK-SAME: i32 trunc (i64 sub (i64 ptrtoint (void ()* @vfunc1 to i64), i64 ptrtoint ({ [2 x i32] }* @vtableB to i64)) to i32),
; CHECK-SAME: i32 trunc (i64 sub (i64 ptrtoint (void ()* @vfunc2 to i64), i64 ptrtoint ({ [2 x i32] }* @vtableB to i64)) to i32)
; CHECK-SAME: i32 trunc (i64 sub (i64 ptrtoint (ptr @vfunc1 to i64), i64 ptrtoint (ptr @vtableB to i64)) to i32),
; CHECK-SAME: i32 trunc (i64 sub (i64 ptrtoint (ptr @vfunc2 to i64), i64 ptrtoint (ptr @vtableB to i64)) to i32)
; CHECK-SAME: ] }, align 8
define internal void @vfunc1() {
@ -33,10 +33,10 @@ define internal void @vfunc2() {
}
define void @main() {
%1 = ptrtoint { [2 x i32] }* @vtableA to i64 ; to keep @vtableA alive
%2 = ptrtoint { [2 x i32] }* @vtableB to i64 ; to keep @vtableB alive
%3 = tail call { i8*, i1 } @llvm.type.checked.load(i8* null, i32 0, metadata !"vfunc1.type")
%4 = tail call { i8*, i1 } @llvm.type.checked.load(i8* null, i32 0, metadata !"vfunc2.type")
%1 = ptrtoint ptr @vtableA to i64 ; to keep @vtableA alive
%2 = ptrtoint ptr @vtableB to i64 ; to keep @vtableB alive
%3 = tail call { ptr, i1 } @llvm.type.checked.load(ptr null, i32 0, metadata !"vfunc1.type")
%4 = tail call { ptr, i1 } @llvm.type.checked.load(ptr null, i32 0, metadata !"vfunc2.type")
ret void
}

View File

@ -4,8 +4,8 @@
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
declare dso_local noalias nonnull i8* @_Znwm(i64)
declare { i8*, i1 } @llvm.type.checked.load(i8*, i32, metadata)
declare dso_local noalias nonnull ptr @_Znwm(i64)
declare { ptr, i1 } @llvm.type.checked.load(ptr, i32, metadata)
; %struct.A is a C++ struct with two virtual functions, A::foo and A::bar. The
; !vcall_visibility metadata is set on the vtable, so we know that all virtual
@ -15,15 +15,15 @@ declare { i8*, i1 } @llvm.type.checked.load(i8*, i32, metadata)
; null.
; However, with the metadata set to 0 we should not perform this VFE.
%struct.A = type { i32 (...)** }
%struct.A = type { ptr }
; We should retain @_ZN1A3barEv in the vtable.
; CHECK: @_ZTV1A = internal unnamed_addr constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* null, i8* bitcast (i32 (%struct.A*)* @_ZN1A3fooEv to i8*), i8* bitcast (i32 (%struct.A*)* @_ZN1A3barEv to i8*)] }
@_ZTV1A = internal unnamed_addr constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* null, i8* bitcast (i32 (%struct.A*)* @_ZN1A3fooEv to i8*), i8* bitcast (i32 (%struct.A*)* @_ZN1A3barEv to i8*)] }, align 8, !type !0, !type !1, !type !2, !vcall_visibility !3
; CHECK: @_ZTV1A = internal unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr null, ptr @_ZN1A3fooEv, ptr @_ZN1A3barEv] }
@_ZTV1A = internal unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr null, ptr @_ZN1A3fooEv, ptr @_ZN1A3barEv] }, align 8, !type !0, !type !1, !type !2, !vcall_visibility !3
; A::foo is called, so must be retained.
; CHECK: define internal i32 @_ZN1A3fooEv(
define internal i32 @_ZN1A3fooEv(%struct.A* nocapture readnone %this) {
define internal i32 @_ZN1A3fooEv(ptr nocapture readnone %this) {
entry:
ret i32 42
}
@ -31,21 +31,18 @@ entry:
; A::bar is not used, so can be deleted with VFE, however, we should not be
; performing that elimination here.
; CHECK: define internal i32 @_ZN1A3barEv(
define internal i32 @_ZN1A3barEv(%struct.A* nocapture readnone %this) {
define internal i32 @_ZN1A3barEv(ptr nocapture readnone %this) {
entry:
ret i32 1337
}
define dso_local i32 @test_A() {
entry:
%call = tail call i8* @_Znwm(i64 8)
%0 = bitcast i8* %call to %struct.A*
%1 = bitcast i8* %call to i32 (...)***
store i32 (...)** bitcast (i8** getelementptr inbounds ({ [4 x i8*] }, { [4 x i8*] }* @_ZTV1A, i64 0, inrange i32 0, i64 2) to i32 (...)**), i32 (...)*** %1, align 8
%2 = tail call { i8*, i1 } @llvm.type.checked.load(i8* bitcast (i8** getelementptr inbounds ({ [4 x i8*] }, { [4 x i8*] }* @_ZTV1A, i64 0, inrange i32 0, i64 2) to i8*), i32 0, metadata !"_ZTS1A"), !nosanitize !9
%3 = extractvalue { i8*, i1 } %2, 0, !nosanitize !9
%4 = bitcast i8* %3 to i32 (%struct.A*)*, !nosanitize !9
%call1 = tail call i32 %4(%struct.A* nonnull %0)
%call = tail call ptr @_Znwm(i64 8)
store ptr getelementptr inbounds ({ [4 x ptr] }, ptr @_ZTV1A, i64 0, inrange i32 0, i64 2), ptr %call, align 8
%0 = tail call { ptr, i1 } @llvm.type.checked.load(ptr getelementptr inbounds ({ [4 x ptr] }, ptr @_ZTV1A, i64 0, inrange i32 0, i64 2), i32 0, metadata !"_ZTS1A"), !nosanitize !9
%1 = extractvalue { ptr, i1 } %0, 0, !nosanitize !9
%call1 = tail call i32 %1(ptr nonnull %call)
ret i32 %call1
}

View File

@ -2,26 +2,26 @@
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
declare { i8*, i1 } @llvm.type.checked.load(i8*, i32, metadata)
declare { ptr, i1 } @llvm.type.checked.load(ptr, i32, metadata)
@vtableA = internal unnamed_addr constant { [2 x i8*] } { [2 x i8*] [
i8* null,
i8* bitcast (void ()* @vfunc2 to i8*)
@vtableA = internal unnamed_addr constant { [2 x ptr] } { [2 x ptr] [
ptr null,
ptr @vfunc2
]}, align 8, !type !{i64 0, !"vfunc1.type"}, !type !{i64 8, !"vfunc2.type"}, !vcall_visibility !{i64 2}
; CHECK: @vtableA = internal unnamed_addr constant { [2 x i8*] } { [2 x i8*] [
; CHECK-SAME: i8* null,
; CHECK-SAME: i8* bitcast (void ()* @vfunc2 to i8*)
; CHECK: @vtableA = internal unnamed_addr constant { [2 x ptr] } { [2 x ptr] [
; CHECK-SAME: ptr null,
; CHECK-SAME: ptr @vfunc2
; CHECK-SAME: ] }, align 8
@vtableB = internal unnamed_addr constant { [2 x i8*] } { [2 x i8*] [
i8* bitcast (void ()* @vfunc1 to i8*),
i8* bitcast (void ()* @vfunc2 to i8*)
@vtableB = internal unnamed_addr constant { [2 x ptr] } { [2 x ptr] [
ptr @vfunc1,
ptr @vfunc2
]}, align 8, !type !{i64 0, !"vfunc1.type"}, !type !{i64 8, !"vfunc2.type"}, !vcall_visibility !{i64 2}
; CHECK: @vtableB = internal unnamed_addr constant { [2 x i8*] } { [2 x i8*] [
; CHECK-SAME: i8* bitcast (void ()* @vfunc1 to i8*),
; CHECK-SAME: i8* bitcast (void ()* @vfunc2 to i8*)
; CHECK: @vtableB = internal unnamed_addr constant { [2 x ptr] } { [2 x ptr] [
; CHECK-SAME: ptr @vfunc1,
; CHECK-SAME: ptr @vfunc2
; CHECK-SAME: ] }, align 8
define internal void @vfunc1() {
@ -33,10 +33,10 @@ define internal void @vfunc2() {
}
define void @main() {
%1 = ptrtoint { [2 x i8*] }* @vtableA to i64 ; to keep @vtableA alive
%2 = ptrtoint { [2 x i8*] }* @vtableB to i64 ; to keep @vtableB alive
%3 = tail call { i8*, i1 } @llvm.type.checked.load(i8* null, i32 0, metadata !"vfunc1.type")
%4 = tail call { i8*, i1 } @llvm.type.checked.load(i8* null, i32 0, metadata !"vfunc2.type")
%1 = ptrtoint ptr @vtableA to i64 ; to keep @vtableA alive
%2 = ptrtoint ptr @vtableB to i64 ; to keep @vtableB alive
%3 = tail call { ptr, i1 } @llvm.type.checked.load(ptr null, i32 0, metadata !"vfunc1.type")
%4 = tail call { ptr, i1 } @llvm.type.checked.load(ptr null, i32 0, metadata !"vfunc2.type")
ret void
}

View File

@ -2,14 +2,14 @@
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
declare { i8*, i1 } @llvm.type.checked.load(i8*, i32, metadata)
declare { ptr, i1 } @llvm.type.checked.load(ptr, i32, metadata)
@vtable = internal unnamed_addr constant { [3 x i32] } { [3 x i32] [
i32 trunc (i64 sub (i64 ptrtoint (void ()* @vfunc1 to i64), i64 ptrtoint ({ [3 x i32] }* @vtable to i64)) to i32),
i32 trunc (i64 sub (i64 ptrtoint (void ()* @vfunc2 to i64), i64 ptrtoint ({ [3 x i32] }* @vtable to i64)) to i32),
i32 trunc (i64 sub (i64 ptrtoint (ptr @vfunc1 to i64), i64 ptrtoint (ptr @vtable to i64)) to i32),
i32 trunc (i64 sub (i64 ptrtoint (ptr @vfunc2 to i64), i64 ptrtoint (ptr @vtable to i64)) to i32),
; a "bad" relative pointer because it's base is not the @vtable symbol
i32 trunc (i64 sub (i64 ptrtoint (void ()* @weird_ref_1 to i64), i64 ptrtoint (void ()* @weird_ref_2 to i64)) to i32)
i32 trunc (i64 sub (i64 ptrtoint (ptr @weird_ref_1 to i64), i64 ptrtoint (ptr @weird_ref_2 to i64)) to i32)
]}, align 8, !type !0, !type !1, !vcall_visibility !{i64 2}
!0 = !{i64 0, !"vfunc1.type"}
!1 = !{i64 4, !"vfunc2.type"}
@ -22,7 +22,7 @@ define internal void @weird_ref_1() { ret void }
define internal void @weird_ref_2() { ret void }
define void @main() {
%1 = ptrtoint { [3 x i32] }* @vtable to i64 ; to keep @vtable alive
%1 = ptrtoint ptr @vtable to i64 ; to keep @vtable alive
call void @weird_ref_2()
ret void
}

View File

@ -2,20 +2,20 @@
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
declare { i8*, i1 } @llvm.type.checked.load(i8*, i32, metadata)
declare { ptr, i1 } @llvm.type.checked.load(ptr, i32, metadata)
; A vtable with "relative pointers", slots don't contain pointers to implementations, but instead have an i32 offset from the vtable itself to the implementation.
@vtable = internal unnamed_addr constant { [4 x i32] } { [4 x i32] [
i32 42,
i32 1337,
i32 trunc (i64 sub (i64 ptrtoint (void ()* @vfunc1_live to i64), i64 ptrtoint (i32* getelementptr inbounds ({ [4 x i32] }, { [4 x i32] }* @vtable, i32 0, i32 0, i32 2) to i64)) to i32),
i32 trunc (i64 sub (i64 ptrtoint (void ()* @vfunc2_dead to i64), i64 ptrtoint (i32* getelementptr inbounds ({ [4 x i32] }, { [4 x i32] }* @vtable, i32 0, i32 0, i32 2) to i64)) to i32)
i32 trunc (i64 sub (i64 ptrtoint (ptr @vfunc1_live to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [4 x i32] }, ptr @vtable, i32 0, i32 0, i32 2) to i64)) to i32),
i32 trunc (i64 sub (i64 ptrtoint (ptr @vfunc2_dead to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [4 x i32] }, ptr @vtable, i32 0, i32 0, i32 2) to i64)) to i32)
]}, align 8, !type !0, !type !1, !vcall_visibility !{i64 2}
!0 = !{i64 8, !"vfunc1.type"}
!1 = !{i64 12, !"vfunc2.type"}
; CHECK: @vtable = internal unnamed_addr constant { [4 x i32] } { [4 x i32] [
; CHECK-SAME: i32 trunc (i64 sub (i64 ptrtoint (void ()* @vfunc1_live to i64), i64 ptrtoint (i32* getelementptr inbounds ({ [4 x i32] }, { [4 x i32] }* @vtable, i32 0, i32 0, i32 2) to i64)) to i32),
; CHECK-SAME: i32 trunc (i64 sub (i64 ptrtoint (ptr @vfunc1_live to i64), i64 ptrtoint (ptr getelementptr inbounds ({ [4 x i32] }, ptr @vtable, i32 0, i32 0, i32 2) to i64)) to i32),
; CHECK-SAME: i32 0
; CHECK-SAME: ] }, align 8, !type !0, !type !1, !vcall_visibility !2
@ -32,8 +32,8 @@ define internal void @vfunc2_dead() {
}
define void @main() {
%1 = ptrtoint { [4 x i32] }* @vtable to i64 ; to keep @vtable alive
%2 = tail call { i8*, i1 } @llvm.type.checked.load(i8* null, i32 0, metadata !"vfunc1.type")
%1 = ptrtoint ptr @vtable to i64 ; to keep @vtable alive
%2 = tail call { ptr, i1 } @llvm.type.checked.load(ptr null, i32 0, metadata !"vfunc1.type")
ret void
}

View File

@ -2,18 +2,18 @@
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
declare { i8*, i1 } @llvm.type.checked.load(i8*, i32, metadata)
declare { ptr, i1 } @llvm.type.checked.load(ptr, i32, metadata)
; A vtable with "relative pointers", slots don't contain pointers to implementations, but instead have an i32 offset from the vtable itself to the implementation.
@vtable = internal unnamed_addr constant { [2 x i32] } { [2 x i32] [
i32 trunc (i64 sub (i64 ptrtoint (void ()* @vfunc1_live to i64), i64 ptrtoint ({ [2 x i32] }* @vtable to i64)) to i32),
i32 trunc (i64 sub (i64 ptrtoint (void ()* @vfunc2_dead to i64), i64 ptrtoint ({ [2 x i32] }* @vtable to i64)) to i32)
i32 trunc (i64 sub (i64 ptrtoint (ptr @vfunc1_live to i64), i64 ptrtoint (ptr @vtable to i64)) to i32),
i32 trunc (i64 sub (i64 ptrtoint (ptr @vfunc2_dead to i64), i64 ptrtoint (ptr @vtable to i64)) to i32)
]}, align 8, !type !0, !type !1, !vcall_visibility !{i64 2}
!0 = !{i64 0, !"vfunc1.type"}
!1 = !{i64 4, !"vfunc2.type"}
; CHECK: @vtable = internal unnamed_addr constant { [2 x i32] } { [2 x i32] [
; CHECK-SAME: i32 trunc (i64 sub (i64 ptrtoint (void ()* @vfunc1_live to i64), i64 ptrtoint ({ [2 x i32] }* @vtable to i64)) to i32),
; CHECK-SAME: i32 trunc (i64 sub (i64 ptrtoint (ptr @vfunc1_live to i64), i64 ptrtoint (ptr @vtable to i64)) to i32),
; CHECK-SAME: i32 0
; CHECK-SAME: ] }, align 8, !type !0, !type !1, !vcall_visibility !2
@ -30,8 +30,8 @@ define internal void @vfunc2_dead() {
}
define void @main() {
%1 = ptrtoint { [2 x i32] }* @vtable to i64 ; to keep @vtable alive
%2 = tail call { i8*, i1 } @llvm.type.checked.load(i8* null, i32 0, metadata !"vfunc1.type")
%1 = ptrtoint ptr @vtable to i64 ; to keep @vtable alive
%2 = tail call { ptr, i1 } @llvm.type.checked.load(ptr null, i32 0, metadata !"vfunc1.type")
ret void
}

View File

@ -6,84 +6,78 @@
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
%struct.A = type { i32 (...)** }
%struct.A = type { ptr }
@_ZTV1A = hidden unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* null, i8* bitcast (void (%struct.A*)* @_ZN1A3fooEv to i8*)] }, align 8, !type !0, !type !1, !vcall_visibility !2
@_ZTV1A = hidden unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr null, ptr @_ZN1A3fooEv] }, align 8, !type !0, !type !1, !vcall_visibility !2
define internal void @_ZN1AC2Ev(%struct.A* %this) {
define internal void @_ZN1AC2Ev(ptr %this) {
entry:
%0 = getelementptr inbounds %struct.A, %struct.A* %this, i64 0, i32 0
store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTV1A, i64 0, inrange i32 0, i64 2) to i32 (...)**), i32 (...)*** %0, align 8
store ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTV1A, i64 0, inrange i32 0, i64 2), ptr %this, align 8
ret void
}
; CHECK: define {{.*}} @_ZN1A3fooEv(
define internal void @_ZN1A3fooEv(%struct.A* nocapture %this) {
define internal void @_ZN1A3fooEv(ptr nocapture %this) {
entry:
ret void
}
define dso_local i8* @_Z6make_Av() {
define dso_local ptr @_Z6make_Av() {
entry:
%call = tail call i8* @_Znwm(i64 8)
%0 = bitcast i8* %call to %struct.A*
tail call void @_ZN1AC2Ev(%struct.A* %0)
ret i8* %call
%call = tail call ptr @_Znwm(i64 8)
tail call void @_ZN1AC2Ev(ptr %call)
ret ptr %call
}
%struct.B = type { i32 (...)** }
%struct.B = type { ptr }
@_ZTV1B = hidden unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* null, i8* bitcast (void (%struct.B*)* @_ZN1B3fooEv to i8*)] }, align 8, !type !0, !type !1, !vcall_visibility !3
@_ZTV1B = hidden unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr null, ptr @_ZN1B3fooEv] }, align 8, !type !0, !type !1, !vcall_visibility !3
define internal void @_ZN1BC2Ev(%struct.B* %this) {
define internal void @_ZN1BC2Ev(ptr %this) {
entry:
%0 = getelementptr inbounds %struct.B, %struct.B* %this, i64 0, i32 0
store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTV1B, i64 0, inrange i32 0, i64 2) to i32 (...)**), i32 (...)*** %0, align 8
store ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTV1B, i64 0, inrange i32 0, i64 2), ptr %this, align 8
ret void
}
; CHECK-NOT: define {{.*}} @_ZN1B3fooEv(
define internal void @_ZN1B3fooEv(%struct.B* nocapture %this) {
define internal void @_ZN1B3fooEv(ptr nocapture %this) {
entry:
ret void
}
define dso_local i8* @_Z6make_Bv() {
define dso_local ptr @_Z6make_Bv() {
entry:
%call = tail call i8* @_Znwm(i64 8)
%0 = bitcast i8* %call to %struct.B*
tail call void @_ZN1BC2Ev(%struct.B* %0)
ret i8* %call
%call = tail call ptr @_Znwm(i64 8)
tail call void @_ZN1BC2Ev(ptr %call)
ret ptr %call
}
%struct.C = type { i32 (...)** }
%struct.C = type { ptr }
@_ZTV1C = hidden unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* null, i8* bitcast (void (%struct.C*)* @_ZN1C3fooEv to i8*)] }, align 8, !type !0, !type !1, !vcall_visibility !4
@_ZTV1C = hidden unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr null, ptr @_ZN1C3fooEv] }, align 8, !type !0, !type !1, !vcall_visibility !4
define internal void @_ZN1CC2Ev(%struct.C* %this) {
define internal void @_ZN1CC2Ev(ptr %this) {
entry:
%0 = getelementptr inbounds %struct.C, %struct.C* %this, i64 0, i32 0
store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTV1C, i64 0, inrange i32 0, i64 2) to i32 (...)**), i32 (...)*** %0, align 8
store ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTV1C, i64 0, inrange i32 0, i64 2), ptr %this, align 8
ret void
}
; CHECK-NOT: define {{.*}} @_ZN1C3fooEv(
define internal void @_ZN1C3fooEv(%struct.C* nocapture %this) {
define internal void @_ZN1C3fooEv(ptr nocapture %this) {
entry:
ret void
}
define dso_local i8* @_Z6make_Cv() {
define dso_local ptr @_Z6make_Cv() {
entry:
%call = tail call i8* @_Znwm(i64 8)
%0 = bitcast i8* %call to %struct.C*
tail call void @_ZN1CC2Ev(%struct.C* %0)
ret i8* %call
%call = tail call ptr @_Znwm(i64 8)
tail call void @_ZN1CC2Ev(ptr %call)
ret ptr %call
}
declare dso_local noalias nonnull i8* @_Znwm(i64)
declare dso_local noalias nonnull ptr @_Znwm(i64)
!llvm.module.flags = !{!5, !6}

View File

@ -6,84 +6,78 @@
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
%struct.A = type { i32 (...)** }
%struct.A = type { ptr }
@_ZTV1A = hidden unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* null, i8* bitcast (void (%struct.A*)* @_ZN1A3fooEv to i8*)] }, align 8, !type !0, !type !1, !vcall_visibility !2
@_ZTV1A = hidden unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr null, ptr @_ZN1A3fooEv] }, align 8, !type !0, !type !1, !vcall_visibility !2
define internal void @_ZN1AC2Ev(%struct.A* %this) {
define internal void @_ZN1AC2Ev(ptr %this) {
entry:
%0 = getelementptr inbounds %struct.A, %struct.A* %this, i64 0, i32 0
store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTV1A, i64 0, inrange i32 0, i64 2) to i32 (...)**), i32 (...)*** %0, align 8
store ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTV1A, i64 0, inrange i32 0, i64 2), ptr %this, align 8
ret void
}
; CHECK: define {{.*}} @_ZN1A3fooEv(
define internal void @_ZN1A3fooEv(%struct.A* nocapture %this) {
define internal void @_ZN1A3fooEv(ptr nocapture %this) {
entry:
ret void
}
define dso_local i8* @_Z6make_Av() {
define dso_local ptr @_Z6make_Av() {
entry:
%call = tail call i8* @_Znwm(i64 8)
%0 = bitcast i8* %call to %struct.A*
tail call void @_ZN1AC2Ev(%struct.A* %0)
ret i8* %call
%call = tail call ptr @_Znwm(i64 8)
tail call void @_ZN1AC2Ev(ptr %call)
ret ptr %call
}
%struct.B = type { i32 (...)** }
%struct.B = type { ptr }
@_ZTV1B = hidden unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* null, i8* bitcast (void (%struct.B*)* @_ZN1B3fooEv to i8*)] }, align 8, !type !0, !type !1, !vcall_visibility !3
@_ZTV1B = hidden unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr null, ptr @_ZN1B3fooEv] }, align 8, !type !0, !type !1, !vcall_visibility !3
define internal void @_ZN1BC2Ev(%struct.B* %this) {
define internal void @_ZN1BC2Ev(ptr %this) {
entry:
%0 = getelementptr inbounds %struct.B, %struct.B* %this, i64 0, i32 0
store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTV1B, i64 0, inrange i32 0, i64 2) to i32 (...)**), i32 (...)*** %0, align 8
store ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTV1B, i64 0, inrange i32 0, i64 2), ptr %this, align 8
ret void
}
; CHECK: define {{.*}} @_ZN1B3fooEv(
define internal void @_ZN1B3fooEv(%struct.B* nocapture %this) {
define internal void @_ZN1B3fooEv(ptr nocapture %this) {
entry:
ret void
}
define dso_local i8* @_Z6make_Bv() {
define dso_local ptr @_Z6make_Bv() {
entry:
%call = tail call i8* @_Znwm(i64 8)
%0 = bitcast i8* %call to %struct.B*
tail call void @_ZN1BC2Ev(%struct.B* %0)
ret i8* %call
%call = tail call ptr @_Znwm(i64 8)
tail call void @_ZN1BC2Ev(ptr %call)
ret ptr %call
}
%struct.C = type { i32 (...)** }
%struct.C = type { ptr }
@_ZTV1C = hidden unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* null, i8* bitcast (void (%struct.C*)* @_ZN1C3fooEv to i8*)] }, align 8, !type !0, !type !1, !vcall_visibility !4
@_ZTV1C = hidden unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr null, ptr @_ZN1C3fooEv] }, align 8, !type !0, !type !1, !vcall_visibility !4
define internal void @_ZN1CC2Ev(%struct.C* %this) {
define internal void @_ZN1CC2Ev(ptr %this) {
entry:
%0 = getelementptr inbounds %struct.C, %struct.C* %this, i64 0, i32 0
store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTV1C, i64 0, inrange i32 0, i64 2) to i32 (...)**), i32 (...)*** %0, align 8
store ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTV1C, i64 0, inrange i32 0, i64 2), ptr %this, align 8
ret void
}
; CHECK-NOT: define {{.*}} @_ZN1C3fooEv(
define internal void @_ZN1C3fooEv(%struct.C* nocapture %this) {
define internal void @_ZN1C3fooEv(ptr nocapture %this) {
entry:
ret void
}
define dso_local i8* @_Z6make_Cv() {
define dso_local ptr @_Z6make_Cv() {
entry:
%call = tail call i8* @_Znwm(i64 8)
%0 = bitcast i8* %call to %struct.C*
tail call void @_ZN1CC2Ev(%struct.C* %0)
ret i8* %call
%call = tail call ptr @_Znwm(i64 8)
tail call void @_ZN1CC2Ev(ptr %call)
ret ptr %call
}
declare dso_local noalias nonnull i8* @_Znwm(i64)
declare dso_local noalias nonnull ptr @_Znwm(i64)
!llvm.module.flags = !{!5}

View File

@ -2,8 +2,8 @@
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
declare dso_local noalias nonnull i8* @_Znwm(i64)
declare { i8*, i1 } @llvm.type.checked.load(i8*, i32, metadata)
declare dso_local noalias nonnull ptr @_Znwm(i64)
declare { ptr, i1 } @llvm.type.checked.load(ptr, i32, metadata)
; %struct.A is a C++ struct with two virtual functions, A::foo and A::bar. The
; !vcall_visibility metadata is set on the vtable, so we know that all virtual
@ -12,39 +12,36 @@ declare { i8*, i1 } @llvm.type.checked.load(i8*, i32, metadata)
; A::bar anywhere, so A::bar can be deleted, and its vtable slot replaced with
; null.
%struct.A = type { i32 (...)** }
%struct.A = type { ptr }
; The pointer to A::bar in the vtable can be removed, because it will never be
; loaded. We replace it with null to keep the layout the same. Because it is at
; the end of the vtable we could potentially shrink the vtable, but don't
; currently do that.
; CHECK: @_ZTV1A = internal unnamed_addr constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* null, i8* bitcast (i32 (%struct.A*)* @_ZN1A3fooEv to i8*), i8* null] }
@_ZTV1A = internal unnamed_addr constant { [4 x i8*] } { [4 x i8*] [i8* null, i8* null, i8* bitcast (i32 (%struct.A*)* @_ZN1A3fooEv to i8*), i8* bitcast (i32 (%struct.A*)* @_ZN1A3barEv to i8*)] }, align 8, !type !0, !type !1, !type !2, !vcall_visibility !3
; CHECK: @_ZTV1A = internal unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr null, ptr @_ZN1A3fooEv, ptr null] }
@_ZTV1A = internal unnamed_addr constant { [4 x ptr] } { [4 x ptr] [ptr null, ptr null, ptr @_ZN1A3fooEv, ptr @_ZN1A3barEv] }, align 8, !type !0, !type !1, !type !2, !vcall_visibility !3
; A::foo is called, so must be retained.
; CHECK: define internal i32 @_ZN1A3fooEv(
define internal i32 @_ZN1A3fooEv(%struct.A* nocapture readnone %this) {
define internal i32 @_ZN1A3fooEv(ptr nocapture readnone %this) {
entry:
ret i32 42
}
; A::bar is not used, so can be deleted.
; CHECK-NOT: define internal i32 @_ZN1A3barEv(
define internal i32 @_ZN1A3barEv(%struct.A* nocapture readnone %this) {
define internal i32 @_ZN1A3barEv(ptr nocapture readnone %this) {
entry:
ret i32 1337
}
define dso_local i32 @test_A() {
entry:
%call = tail call i8* @_Znwm(i64 8)
%0 = bitcast i8* %call to %struct.A*
%1 = bitcast i8* %call to i32 (...)***
store i32 (...)** bitcast (i8** getelementptr inbounds ({ [4 x i8*] }, { [4 x i8*] }* @_ZTV1A, i64 0, inrange i32 0, i64 2) to i32 (...)**), i32 (...)*** %1, align 8
%2 = tail call { i8*, i1 } @llvm.type.checked.load(i8* bitcast (i8** getelementptr inbounds ({ [4 x i8*] }, { [4 x i8*] }* @_ZTV1A, i64 0, inrange i32 0, i64 2) to i8*), i32 0, metadata !"_ZTS1A"), !nosanitize !9
%3 = extractvalue { i8*, i1 } %2, 0, !nosanitize !9
%4 = bitcast i8* %3 to i32 (%struct.A*)*, !nosanitize !9
%call1 = tail call i32 %4(%struct.A* nonnull %0)
%call = tail call ptr @_Znwm(i64 8)
store ptr getelementptr inbounds ({ [4 x ptr] }, ptr @_ZTV1A, i64 0, inrange i32 0, i64 2), ptr %call, align 8
%0 = tail call { ptr, i1 } @llvm.type.checked.load(ptr getelementptr inbounds ({ [4 x ptr] }, ptr @_ZTV1A, i64 0, inrange i32 0, i64 2), i32 0, metadata !"_ZTS1A"), !nosanitize !9
%1 = extractvalue { ptr, i1 } %0, 0, !nosanitize !9
%call1 = tail call i32 %1(ptr nonnull %call)
ret i32 %call1
}

View File

@ -6,38 +6,36 @@
target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
%struct.A = type { i32 (...)** }
%struct.A = type { ptr }
; CHECK: @_ZTV1A = hidden unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* bitcast ({ i8*, i8* }* @_ZTI1A to i8*), i8* null] }, align 8, !type !0, !type !1, !vcall_visibility !2
; CHECK: @_ZTV1A = hidden unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr @_ZTI1A, ptr null] }, align 8, !type !0, !type !1, !vcall_visibility !2
@_ZTV1A = hidden unnamed_addr constant { [3 x i8*] } { [3 x i8*] [i8* null, i8* bitcast ({ i8*, i8* }* @_ZTI1A to i8*), i8* bitcast (void (%struct.A*)* @_ZN1A3fooEv to i8*)] }, align 8, !type !0, !type !1, !vcall_visibility !2
@_ZTV1A = hidden unnamed_addr constant { [3 x ptr] } { [3 x ptr] [ptr null, ptr @_ZTI1A, ptr @_ZN1A3fooEv] }, align 8, !type !0, !type !1, !vcall_visibility !2
@_ZTS1A = hidden constant [3 x i8] c"1A\00", align 1
@_ZTI1A = hidden constant { i8*, i8* } { i8* bitcast (i8** getelementptr inbounds (i8*, i8** @_ZTVN10__cxxabiv117__class_type_infoE, i64 2) to i8*), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @_ZTS1A, i32 0, i32 0) }, align 8
@_ZTI1A = hidden constant { ptr, ptr } { ptr getelementptr inbounds (ptr, ptr @_ZTVN10__cxxabiv117__class_type_infoE, i64 2), ptr @_ZTS1A }, align 8
define internal void @_ZN1AC2Ev(%struct.A* %this) {
define internal void @_ZN1AC2Ev(ptr %this) {
entry:
%0 = getelementptr inbounds %struct.A, %struct.A* %this, i64 0, i32 0
store i32 (...)** bitcast (i8** getelementptr inbounds ({ [3 x i8*] }, { [3 x i8*] }* @_ZTV1A, i64 0, inrange i32 0, i64 2) to i32 (...)**), i32 (...)*** %0, align 8
store ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTV1A, i64 0, inrange i32 0, i64 2), ptr %this, align 8
ret void
}
; CHECK-NOT: define {{.*}} @_ZN1A3fooEv(
define internal void @_ZN1A3fooEv(%struct.A* nocapture %this) {
define internal void @_ZN1A3fooEv(ptr nocapture %this) {
entry:
ret void
}
define dso_local i8* @_Z6make_Av() {
define dso_local ptr @_Z6make_Av() {
entry:
%call = tail call i8* @_Znwm(i64 8)
%0 = bitcast i8* %call to %struct.A*
tail call void @_ZN1AC2Ev(%struct.A* %0)
ret i8* %call
%call = tail call ptr @_Znwm(i64 8)
tail call void @_ZN1AC2Ev(ptr %call)
ret ptr %call
}
declare dso_local noalias nonnull i8* @_Znwm(i64)
@_ZTVN10__cxxabiv117__class_type_infoE = external dso_local global i8*
declare dso_local noalias nonnull ptr @_Znwm(i64)
@_ZTVN10__cxxabiv117__class_type_infoE = external dso_local global ptr
!llvm.module.flags = !{!3, !4}