1; -stats requires asserts 2; REQUIRES: asserts 3 4; RUN: opt -S -passes=wholeprogramdevirt -whole-program-visibility -pass-remarks=wholeprogramdevirt -stats %s 2>&1 | FileCheck %s 5; Skipping vf0i1 is identical to setting public LTO visibility. We don't devirtualize vf0i1 and all other 6; virtual call targets. 7; RUN: opt -S -passes=wholeprogramdevirt -whole-program-visibility -pass-remarks=wholeprogramdevirt -wholeprogramdevirt-skip=vf0i1 %s 2>&1 | FileCheck %s --check-prefix=SKIP 8; We have two set of call targets {vf0i1, vf1i1} and {vf1i32, vf2i32, vf3i32, vf4i32}. 9; The command below prevents both of them from devirtualization. 10; RUN: opt -S -passes=wholeprogramdevirt -whole-program-visibility -pass-remarks=wholeprogramdevirt -wholeprogramdevirt-skip=vf0i1,vf1i32 %s 2>&1 | FileCheck %s --check-prefix=SKIP-ALL 11; Check wildcard 12; RUN: opt -S -passes=wholeprogramdevirt -whole-program-visibility -pass-remarks=wholeprogramdevirt -wholeprogramdevirt-skip=vf?i1 %s 2>&1 | FileCheck %s --check-prefix=SKIP 13 14target datalayout = "e-p:64:64" 15target triple = "x86_64-unknown-linux-gnu" 16 17; CHECK: remark: <unknown>:0:0: virtual-const-prop-1-bit: devirtualized a call to vf0i1 18; CHECK: remark: <unknown>:0:0: virtual-const-prop-1-bit: devirtualized a call to vf1i1 19; CHECK: remark: <unknown>:0:0: virtual-const-prop: devirtualized a call to vf1i32 20; CHECK: remark: <unknown>:0:0: devirtualized vf0i1 21; CHECK: remark: <unknown>:0:0: devirtualized vf1i1 22; CHECK: remark: <unknown>:0:0: devirtualized vf1i32 23; CHECK: remark: <unknown>:0:0: devirtualized vf2i32 24; CHECK: remark: <unknown>:0:0: devirtualized vf3i32 25; CHECK: remark: <unknown>:0:0: devirtualized vf4i32 26; CHECK-NOT: devirtualized 27 28; SKIP: remark: <unknown>:0:0: virtual-const-prop: devirtualized a call to vf1i32 29; SKIP: remark: <unknown>:0:0: devirtualized vf1i32 30; SKIP: remark: <unknown>:0:0: devirtualized vf2i32 31; SKIP: remark: <unknown>:0:0: devirtualized vf3i32 32; SKIP: remark: <unknown>:0:0: devirtualized vf4i32 33; SKIP-NOT: devirtualized 34 35; SKIP-ALL-NOT: devirtualized 36 37; CHECK: [[VT1DATA:@[^ ]*]] = private constant { [8 x i8], [3 x i8*], [0 x i8] } { [8 x i8] c"\00\00\00\01\00\00\00\02", [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]+]] 38@vt1 = constant [3 x i8*] [ 39i8* bitcast (i1 (i8*)* @vf0i1 to i8*), 40i8* bitcast (i1 (i8*)* @vf1i1 to i8*), 41i8* bitcast (i32 (i8*)* @vf1i32 to i8*) 42], section "vt1sec", !type !0 43 44; CHECK: [[VT2DATA:@[^ ]*]] = private constant { [8 x i8], [3 x i8*], [0 x i8] } { [8 x i8] c"\00\00\00\02\00\00\00\01", [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]] 45@vt2 = constant [3 x i8*] [ 46i8* bitcast (i1 (i8*)* @vf1i1 to i8*), 47i8* bitcast (i1 (i8*)* @vf0i1 to i8*), 48i8* bitcast (i32 (i8*)* @vf2i32 to i8*) 49], !type !0 50 51; CHECK: [[VT3DATA:@[^ ]*]] = private constant { [8 x i8], [3 x i8*], [0 x i8] } { [8 x i8] c"\00\00\00\03\00\00\00\02", [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]] 52@vt3 = constant [3 x i8*] [ 53i8* bitcast (i1 (i8*)* @vf0i1 to i8*), 54i8* bitcast (i1 (i8*)* @vf1i1 to i8*), 55i8* bitcast (i32 (i8*)* @vf3i32 to i8*) 56], !type !0 57 58; CHECK: [[VT4DATA:@[^ ]*]] = private constant { [8 x i8], [3 x i8*], [0 x i8] } { [8 x i8] c"\00\00\00\04\00\00\00\01", [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]] 59@vt4 = constant [3 x i8*] [ 60i8* bitcast (i1 (i8*)* @vf1i1 to i8*), 61i8* bitcast (i1 (i8*)* @vf0i1 to i8*), 62i8* bitcast (i32 (i8*)* @vf4i32 to i8*) 63], !type !0 64 65; CHECK: @vt5 = {{.*}}, !type [[T0:![0-9]+]] 66@vt5 = constant [3 x i8*] [ 67i8* bitcast (void ()* @__cxa_pure_virtual to i8*), 68i8* bitcast (void ()* @__cxa_pure_virtual to i8*), 69i8* bitcast (void ()* @__cxa_pure_virtual to i8*) 70], !type !0 71 72; 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) 73; 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) 74; 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) 75; 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) 76 77define i1 @vf0i1(i8* %this) readnone { 78 ret i1 0 79} 80 81define i1 @vf1i1(i8* %this) readnone { 82 ret i1 1 83} 84 85define i32 @vf1i32(i8* %this) readnone { 86 ret i32 1 87} 88 89define i32 @vf2i32(i8* %this) readnone { 90 ret i32 2 91} 92 93define i32 @vf3i32(i8* %this) readnone { 94 ret i32 3 95} 96 97define i32 @vf4i32(i8* %this) readnone { 98 ret i32 4 99} 100 101; CHECK: define i1 @call1( 102define i1 @call1(i8* %obj) { 103 %vtableptr = bitcast i8* %obj to [3 x i8*]** 104 %vtable = load [3 x i8*]*, [3 x i8*]** %vtableptr 105 ; CHECK: [[VT1:%[^ ]*]] = bitcast [3 x i8*]* {{.*}} to i8* 106 %vtablei8 = bitcast [3 x i8*]* %vtable to i8* 107 %pair = call {i8*, i1} @llvm.type.checked.load(i8* %vtablei8, i32 0, metadata !"typeid") 108 %fptr = extractvalue {i8*, i1} %pair, 0 109 %fptr_casted = bitcast i8* %fptr to i1 (i8*)* 110 ; CHECK: [[VTGEP1:%[^ ]*]] = getelementptr i8, i8* [[VT1]], i32 -1 111 ; CHECK: [[VTLOAD1:%[^ ]*]] = load i8, i8* [[VTGEP1]] 112 ; CHECK: [[VTAND1:%[^ ]*]] = and i8 [[VTLOAD1]], 1 113 ; CHECK: [[VTCMP1:%[^ ]*]] = icmp ne i8 [[VTAND1]], 0 114 %result = call i1 %fptr_casted(i8* %obj) 115 ; CHECK: [[AND1:%[^ ]*]] = and i1 [[VTCMP1]], true 116 %p = extractvalue {i8*, i1} %pair, 1 117 %and = and i1 %result, %p 118 ; CHECK: ret i1 [[AND1]] 119 ret i1 %and 120} 121 122; CHECK: define i1 @call2( 123define i1 @call2(i8* %obj) { 124 %vtableptr = bitcast i8* %obj to [3 x i8*]** 125 %vtable = load [3 x i8*]*, [3 x i8*]** %vtableptr 126 ; CHECK: [[VT2:%[^ ]*]] = bitcast [3 x i8*]* {{.*}} to i8* 127 %vtablei8 = bitcast [3 x i8*]* %vtable to i8* 128 %pair = call {i8*, i1} @llvm.type.checked.load(i8* %vtablei8, i32 8, metadata !"typeid") 129 %fptr = extractvalue {i8*, i1} %pair, 0 130 %fptr_casted = bitcast i8* %fptr to i1 (i8*)* 131 ; CHECK: [[VTGEP2:%[^ ]*]] = getelementptr i8, i8* [[VT2]], i32 -1 132 ; CHECK: [[VTLOAD2:%[^ ]*]] = load i8, i8* [[VTGEP2]] 133 ; CHECK: [[VTAND2:%[^ ]*]] = and i8 [[VTLOAD2]], 2 134 ; CHECK: [[VTCMP2:%[^ ]*]] = icmp ne i8 [[VTAND2]], 0 135 %result = call i1 %fptr_casted(i8* %obj) 136 ; CHECK: [[AND2:%[^ ]*]] = and i1 [[VTCMP2]], true 137 %p = extractvalue {i8*, i1} %pair, 1 138 %and = and i1 %result, %p 139 ; CHECK: ret i1 [[AND2]] 140 ret i1 %and 141} 142 143; CHECK: define i32 @call3( 144define i32 @call3(i8* %obj) { 145 %vtableptr = bitcast i8* %obj to [3 x i8*]** 146 %vtable = load [3 x i8*]*, [3 x i8*]** %vtableptr 147 ; CHECK: [[VT3:%[^ ]*]] = bitcast [3 x i8*]* {{.*}} to i8* 148 %vtablei8 = bitcast [3 x i8*]* %vtable to i8* 149 %pair = call {i8*, i1} @llvm.type.checked.load(i8* %vtablei8, i32 16, metadata !"typeid") 150 %fptr = extractvalue {i8*, i1} %pair, 0 151 %fptr_casted = bitcast i8* %fptr to i32 (i8*)* 152 ; CHECK: [[VTGEP3:%[^ ]*]] = getelementptr i8, i8* [[VT3]], i32 -5 153 ; CHECK: [[VTBC3:%[^ ]*]] = bitcast i8* [[VTGEP3]] to i32* 154 ; CHECK: [[VTLOAD3:%[^ ]*]] = load i32, i32* [[VTBC3]] 155 %result = call i32 %fptr_casted(i8* %obj) 156 ; CHECK: ret i32 [[VTLOAD3]] 157 ret i32 %result 158} 159 160declare {i8*, i1} @llvm.type.checked.load(i8*, i32, metadata) 161declare void @llvm.assume(i1) 162declare void @__cxa_pure_virtual() 163 164; CHECK: [[T8]] = !{i32 8, !"typeid"} 165; CHECK: [[T0]] = !{i32 0, !"typeid"} 166 167!0 = !{i32 0, !"typeid"} 168 169; CHECK: 6 wholeprogramdevirt - Number of whole program devirtualization targets 170; CHECK: 1 wholeprogramdevirt - Number of virtual constant propagations 171; CHECK: 2 wholeprogramdevirt - Number of 1 bit virtual constant propagations 172