1; RUN: opt -S -wholeprogramdevirt -pass-remarks=wholeprogramdevirt %s 2>&1 | FileCheck %s 2 3target datalayout = "e-p:64:64" 4target triple = "x86_64-unknown-linux-gnu" 5 6; CHECK: remark: <unknown>:0:0: virtual-const-prop: devirtualized a call to vf1i32 7; CHECK: remark: <unknown>:0:0: virtual-const-prop-1-bit: devirtualized a call to vf1i1 8; CHECK: remark: <unknown>:0:0: virtual-const-prop-1-bit: devirtualized a call to vf0i1 9; CHECK: remark: <unknown>:0:0: devirtualized vf0i1 10; CHECK: remark: <unknown>:0:0: devirtualized vf1i1 11; CHECK: remark: <unknown>:0:0: devirtualized vf1i32 12; CHECK: remark: <unknown>:0:0: devirtualized vf2i32 13; CHECK: remark: <unknown>:0:0: devirtualized vf3i32 14; CHECK: remark: <unknown>:0:0: devirtualized vf4i32 15; CHECK-NOT: devirtualized 16 17; CHECK: [[VT1DATA:@[^ ]*]] = private constant { [8 x i8], [3 x i8*], [0 x i8] } { [8 x i8] c"\00\00\00\01\01\00\00\00", [3 x i8*] [i8* bitcast (i1 (i8*)* @vf0i1 to i8*), i8* bitcast (i1 (i8*)* @vf1i1 to i8*), i8* bitcast (i32 (i8*)* @vf1i32 to i8*)], [0 x i8] zeroinitializer }, section "vt1sec", !type [[T8:![0-9]+]] 18@vt1 = constant [3 x i8*] [ 19i8* bitcast (i1 (i8*)* @vf0i1 to i8*), 20i8* bitcast (i1 (i8*)* @vf1i1 to i8*), 21i8* bitcast (i32 (i8*)* @vf1i32 to i8*) 22], section "vt1sec", !type !0 23 24; CHECK: [[VT2DATA:@[^ ]*]] = private constant { [8 x i8], [3 x i8*], [0 x i8] } { [8 x i8] c"\00\00\00\02\02\00\00\00", [3 x i8*] [i8* bitcast (i1 (i8*)* @vf1i1 to i8*), i8* bitcast (i1 (i8*)* @vf0i1 to i8*), i8* bitcast (i32 (i8*)* @vf2i32 to i8*)], [0 x i8] zeroinitializer }, !type [[T8]] 25@vt2 = constant [3 x i8*] [ 26i8* bitcast (i1 (i8*)* @vf1i1 to i8*), 27i8* bitcast (i1 (i8*)* @vf0i1 to i8*), 28i8* bitcast (i32 (i8*)* @vf2i32 to i8*) 29], !type !0 30 31; CHECK: [[VT3DATA:@[^ ]*]] = private constant { [8 x i8], [3 x i8*], [0 x i8] } { [8 x i8] c"\00\00\00\01\03\00\00\00", [3 x i8*] [i8* bitcast (i1 (i8*)* @vf0i1 to i8*), i8* bitcast (i1 (i8*)* @vf1i1 to i8*), i8* bitcast (i32 (i8*)* @vf3i32 to i8*)], [0 x i8] zeroinitializer }, !type [[T8]] 32@vt3 = constant [3 x i8*] [ 33i8* bitcast (i1 (i8*)* @vf0i1 to i8*), 34i8* bitcast (i1 (i8*)* @vf1i1 to i8*), 35i8* bitcast (i32 (i8*)* @vf3i32 to i8*) 36], !type !0 37 38; CHECK: [[VT4DATA:@[^ ]*]] = private constant { [8 x i8], [3 x i8*], [0 x i8] } { [8 x i8] c"\00\00\00\02\04\00\00\00", [3 x i8*] [i8* bitcast (i1 (i8*)* @vf1i1 to i8*), i8* bitcast (i1 (i8*)* @vf0i1 to i8*), i8* bitcast (i32 (i8*)* @vf4i32 to i8*)], [0 x i8] zeroinitializer }, !type [[T8]] 39@vt4 = constant [3 x i8*] [ 40i8* bitcast (i1 (i8*)* @vf1i1 to i8*), 41i8* bitcast (i1 (i8*)* @vf0i1 to i8*), 42i8* bitcast (i32 (i8*)* @vf4i32 to i8*) 43], !type !0 44 45; CHECK: @vt5 = {{.*}}, !type [[T0:![0-9]+]] 46@vt5 = constant [3 x i8*] [ 47i8* bitcast (void ()* @__cxa_pure_virtual to i8*), 48i8* bitcast (void ()* @__cxa_pure_virtual to i8*), 49i8* bitcast (void ()* @__cxa_pure_virtual to i8*) 50], !type !0 51 52; CHECK: @vt1 = alias [3 x i8*], getelementptr inbounds ({ [8 x i8], [3 x i8*], [0 x i8] }, { [8 x i8], [3 x i8*], [0 x i8] }* [[VT1DATA]], i32 0, i32 1) 53; CHECK: @vt2 = alias [3 x i8*], getelementptr inbounds ({ [8 x i8], [3 x i8*], [0 x i8] }, { [8 x i8], [3 x i8*], [0 x i8] }* [[VT2DATA]], i32 0, i32 1) 54; CHECK: @vt3 = alias [3 x i8*], getelementptr inbounds ({ [8 x i8], [3 x i8*], [0 x i8] }, { [8 x i8], [3 x i8*], [0 x i8] }* [[VT3DATA]], i32 0, i32 1) 55; CHECK: @vt4 = alias [3 x i8*], getelementptr inbounds ({ [8 x i8], [3 x i8*], [0 x i8] }, { [8 x i8], [3 x i8*], [0 x i8] }* [[VT4DATA]], i32 0, i32 1) 56 57define i1 @vf0i1(i8* %this) readnone { 58 ret i1 0 59} 60 61define i1 @vf1i1(i8* %this) readnone { 62 ret i1 1 63} 64 65define i32 @vf1i32(i8* %this) readnone { 66 ret i32 1 67} 68 69define i32 @vf2i32(i8* %this) readnone { 70 ret i32 2 71} 72 73define i32 @vf3i32(i8* %this) readnone { 74 ret i32 3 75} 76 77define i32 @vf4i32(i8* %this) readnone { 78 ret i32 4 79} 80 81; CHECK: define i1 @call1( 82define i1 @call1(i8* %obj) { 83 %vtableptr = bitcast i8* %obj to [3 x i8*]** 84 %vtable = load [3 x i8*]*, [3 x i8*]** %vtableptr 85 ; CHECK: [[VT1:%[^ ]*]] = bitcast [3 x i8*]* {{.*}} to i8* 86 %vtablei8 = bitcast [3 x i8*]* %vtable to i8* 87 %pair = call {i8*, i1} @llvm.type.checked.load(i8* %vtablei8, i32 0, metadata !"typeid") 88 %fptr = extractvalue {i8*, i1} %pair, 0 89 %fptr_casted = bitcast i8* %fptr to i1 (i8*)* 90 ; CHECK: [[VTGEP1:%[^ ]*]] = getelementptr i8, i8* [[VT1]], i64 -5 91 ; CHECK: [[VTLOAD1:%[^ ]*]] = load i8, i8* [[VTGEP1]] 92 ; CHECK: [[VTAND1:%[^ ]*]] = and i8 [[VTLOAD1]], 2 93 ; CHECK: [[VTCMP1:%[^ ]*]] = icmp ne i8 [[VTAND1]], 0 94 %result = call i1 %fptr_casted(i8* %obj) 95 ; CHECK: [[AND1:%[^ ]*]] = and i1 [[VTCMP1]], true 96 %p = extractvalue {i8*, i1} %pair, 1 97 %and = and i1 %result, %p 98 ; CHECK: ret i1 [[AND1]] 99 ret i1 %and 100} 101 102; CHECK: define i1 @call2( 103define i1 @call2(i8* %obj) { 104 %vtableptr = bitcast i8* %obj to [3 x i8*]** 105 %vtable = load [3 x i8*]*, [3 x i8*]** %vtableptr 106 ; CHECK: [[VT2:%[^ ]*]] = bitcast [3 x i8*]* {{.*}} to i8* 107 %vtablei8 = bitcast [3 x i8*]* %vtable to i8* 108 %pair = call {i8*, i1} @llvm.type.checked.load(i8* %vtablei8, i32 8, metadata !"typeid") 109 %fptr = extractvalue {i8*, i1} %pair, 0 110 %fptr_casted = bitcast i8* %fptr to i1 (i8*)* 111 ; CHECK: [[VTGEP2:%[^ ]*]] = getelementptr i8, i8* [[VT2]], i64 -5 112 ; CHECK: [[VTLOAD2:%[^ ]*]] = load i8, i8* [[VTGEP2]] 113 ; CHECK: [[VTAND2:%[^ ]*]] = and i8 [[VTLOAD2]], 1 114 ; CHECK: [[VTCMP2:%[^ ]*]] = icmp ne i8 [[VTAND2]], 0 115 %result = call i1 %fptr_casted(i8* %obj) 116 ; CHECK: [[AND2:%[^ ]*]] = and i1 [[VTCMP2]], true 117 %p = extractvalue {i8*, i1} %pair, 1 118 %and = and i1 %result, %p 119 ; CHECK: ret i1 [[AND2]] 120 ret i1 %and 121} 122 123; CHECK: define i32 @call3( 124define i32 @call3(i8* %obj) { 125 %vtableptr = bitcast i8* %obj to [3 x i8*]** 126 %vtable = load [3 x i8*]*, [3 x i8*]** %vtableptr 127 ; CHECK: [[VT3:%[^ ]*]] = bitcast [3 x i8*]* {{.*}} to i8* 128 %vtablei8 = bitcast [3 x i8*]* %vtable to i8* 129 %pair = call {i8*, i1} @llvm.type.checked.load(i8* %vtablei8, i32 16, metadata !"typeid") 130 %fptr = extractvalue {i8*, i1} %pair, 0 131 %fptr_casted = bitcast i8* %fptr to i32 (i8*)* 132 ; CHECK: [[VTGEP3:%[^ ]*]] = getelementptr i8, i8* [[VT3]], i64 -4 133 ; CHECK: [[VTBC3:%[^ ]*]] = bitcast i8* [[VTGEP3]] to i32* 134 ; CHECK: [[VTLOAD3:%[^ ]*]] = load i32, i32* [[VTBC3]] 135 %result = call i32 %fptr_casted(i8* %obj) 136 ; CHECK: ret i32 [[VTLOAD3]] 137 ret i32 %result 138} 139 140declare {i8*, i1} @llvm.type.checked.load(i8*, i32, metadata) 141declare void @llvm.assume(i1) 142declare void @__cxa_pure_virtual() 143 144; CHECK: [[T8]] = !{i32 8, !"typeid"} 145; CHECK: [[T0]] = !{i32 0, !"typeid"} 146 147!0 = !{i32 0, !"typeid"} 148