1; RUN: opt < %s -pgo-icall-prom -S -icp-total-percent-threshold=10 | FileCheck %s
2; RUN: opt < %s -passes=pgo-icall-prom -S -icp-total-percent-threshold=10 | FileCheck %s
3
4; PR42413: Previously the call promotion code did not correctly update the byval
5; attribute. Check that it does. This situation can come up in LTO scenarios
6; where struct types end up not matching.
7
8target triple = "i686-unknown-linux-gnu"
9
10%struct.Foo.1 = type { i32 }
11%struct.Foo.2 = type { i32 }
12
13@foo = common global i32 (%struct.Foo.2*)* null, align 8
14
15define i32 @func4(%struct.Foo.1* byval(%struct.Foo.1) %p) {
16entry:
17  %gep = getelementptr inbounds %struct.Foo.1, %struct.Foo.1* %p, i32 0, i32 0
18  %v = load i32, i32* %gep
19  ret i32 %v
20}
21
22define i32 @func5(%struct.Foo.1* byval(%struct.Foo.1) %p) {
23entry:
24  %gep = getelementptr inbounds %struct.Foo.1, %struct.Foo.1* %p, i32 0, i32 0
25  %v = load i32, i32* %gep
26  ret i32 %v
27}
28
29define i32 @bar(%struct.Foo.2* %f2) {
30entry:
31  %tmp = load i32 (%struct.Foo.2*)*, i32 (%struct.Foo.2*)** @foo, align 8
32  %call = call i32 %tmp(%struct.Foo.2* byval(%struct.Foo.2) %f2), !prof !1
33  ret i32 %call
34}
35
36!1 = !{!"VP", i32 0, i64 3000, i64 7651369219802541373, i64 1000, i64 3667884930908592509, i64 1000}
37
38
39; CHECK: define i32 @bar(%struct.Foo.2* %f2)
40;     Cast %struct.Foo.2* to %struct.Foo.1* and use byval(%struct.Foo.2).
41; CHECK: %[[cast:[^ ]*]] = bitcast %struct.Foo.2* %f2 to %struct.Foo.1*
42; CHECK: call i32 @func4(%struct.Foo.1* byval(%struct.Foo.1) %[[cast]])
43;     Same but when callee doesn't have explicit byval type.
44; CHECK: %[[cast:[^ ]*]] = bitcast %struct.Foo.2* %f2 to %struct.Foo.1*
45; CHECK: call i32 @func5(%struct.Foo.1* byval(%struct.Foo.1) %[[cast]])
46;     Original call stays the same.
47; CHECK: call i32 %tmp(%struct.Foo.2* byval(%struct.Foo.2) %f2)
48