1; RUN: opt < %s -pgo-icall-prom -S | FileCheck %s --check-prefix=ICALL-PROM
2; RUN: opt < %s -passes=pgo-icall-prom -S | FileCheck %s --check-prefix=ICALL-PROM
3target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
4target triple = "x86_64-unknown-linux-gnu"
5
6%struct.D = type { %struct.B }
7%struct.B = type { i32 (...)** }
8%struct.Base = type { i8 }
9%struct.Derived = type { i8 }
10
11declare noalias i8* @_Znwm(i64)
12declare void @_ZN1DC2Ev(%struct.D*);
13declare %struct.Derived* @_ZN1D4funcEv(%struct.D*);
14
15define %struct.Base* @bar() {
16entry:
17  %call = call noalias i8* @_Znwm(i64 8)
18  %tmp = bitcast i8* %call to %struct.D*
19  call void @_ZN1DC2Ev(%struct.D* %tmp)
20  %tmp1 = bitcast %struct.D* %tmp to %struct.B*
21  %tmp2 = bitcast %struct.B* %tmp1 to %struct.Base* (%struct.B*)***
22  %vtable = load %struct.Base* (%struct.B*)**, %struct.Base* (%struct.B*)*** %tmp2, align 8
23  %vfn = getelementptr inbounds %struct.Base* (%struct.B*)*, %struct.Base* (%struct.B*)** %vtable, i64 0
24  %tmp3 = load %struct.Base* (%struct.B*)*, %struct.Base* (%struct.B*)** %vfn, align 8
25; ICALL-PROM:  [[CMP:%[0-9]+]] = icmp eq %struct.Base* (%struct.B*)* %tmp3, bitcast (%struct.Derived* (%struct.D*)* @_ZN1D4funcEv to %struct.Base* (%struct.B*)*)
26; ICALL-PROM:  br i1 [[CMP]], label %if.true.direct_targ, label %if.false.orig_indirect, !prof [[BRANCH_WEIGHT:![0-9]+]]
27; ICALL-PROM:if.true.direct_targ:
28; ICALL-PROM:  [[ARG_BITCAST:%[0-9]+]] = bitcast %struct.B* %tmp1 to %struct.D*
29; ICALL-PROM:  [[DIRCALL_RET:%[0-9]+]] = call %struct.Derived* @_ZN1D4funcEv(%struct.D* [[ARG_BITCAST]])
30; ICALL-PROM:  [[DIRCALL_RET_CAST:%[0-9]+]] = bitcast %struct.Derived* [[DIRCALL_RET]] to %struct.Base*
31; ICALL-PROM:  br label %if.end.icp
32; ICALL-PROM:if.false.orig_indirect:
33; ICALL-PROM:  %call1 = call %struct.Base* %tmp3(%struct.B* %tmp1)
34; ICALL-PROM:  br label %if.end.icp
35; ICALL-PROM:if.end.icp:
36; ICALL-PROM:  [[PHI_RET:%[0-9]+]] = phi %struct.Base* [ %call1, %if.false.orig_indirect ], [ [[DIRCALL_RET_CAST]], %if.true.direct_targ ]
37  %call1 = call %struct.Base* %tmp3(%struct.B* %tmp1), !prof !1
38  ret %struct.Base* %call1
39}
40
41!1 = !{!"VP", i32 0, i64 12345, i64 -3913987384944532146, i64 12345}
42; ICALL-PROM-NOT: !1 = !{!"VP", i32 0, i64 12345, i64 -3913987384944532146, i64 12345}
43; ICALL-PROM: [[BRANCH_WEIGHT]] = !{!"branch_weights", i32 12345, i32 0}
44; ICALL-PROM-NOT: !1 = !{!"VP", i32 0, i64 12345, i64 -3913987384944532146, i64 12345}
45