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
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.
8 target triple = "i686-unknown-linux-gnu"
10 %struct.Foo.1 = type { i32 }
11 %struct.Foo.2 = type { i32 }
13 @foo = common global i32 (%struct.Foo.2*)* null, align 8
15 define i32 @func4(%struct.Foo.1* byval(%struct.Foo.1) %p) {
17 %gep = getelementptr inbounds %struct.Foo.1, %struct.Foo.1* %p, i32 0, i32 0
18 %v = load i32, i32* %gep
22 define i32 @func5(%struct.Foo.1* byval(%struct.Foo.1) %p) {
24 %gep = getelementptr inbounds %struct.Foo.1, %struct.Foo.1* %p, i32 0, i32 0
25 %v = load i32, i32* %gep
29 define i32 @bar(%struct.Foo.2* %f2) {
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
36 !1 = !{!"VP", i32 0, i64 3000, i64 7651369219802541373, i64 1000, i64 3667884930908592509, i64 1000}
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)