llvm.org GIT mirror llvm / e3eea3c
[PGO] Update ICP pass for recent byval type changes Fixes verifier errors encountered in PR42413. Reviewers: xur, t.p.northover, inglorion, gbiv, george.burgess.iv Differential Revision: https://reviews.llvm.org/D63842 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@364861 91177308-0d34-0410-b5e6-96231b3b80d8 Reid Kleckner 2 months ago
2 changed file(s) with 56 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
411411 // Remove any incompatible attributes for the argument.
412412 AttrBuilder ArgAttrs(CallerPAL.getParamAttributes(ArgNo));
413413 ArgAttrs.remove(AttributeFuncs::typeIncompatible(FormalTy));
414
415 // If byval is used, this must be a pointer type, and the byval type must
416 // match the element type. Update it if present.
417 if (ArgAttrs.getByValType()) {
418 Type *NewTy = Callee->getParamByValType(ArgNo);
419 ArgAttrs.addByValAttr(
420 NewTy ? NewTy : cast(FormalTy)->getElementType());
421 }
422
414423 NewArgAttrs.push_back(AttributeSet::get(Ctx, ArgAttrs));
415424 AttributeChanged = true;
416425 } else
0 ; RUN: opt < %s -pgo-icall-prom -S -icp-total-percent-threshold=10 | FileCheck %s
1 ; RUN: opt < %s -passes=pgo-icall-prom -S -icp-total-percent-threshold=10 | FileCheck %s
2
3 ; PR42413: Previously the call promotion code did not correctly update the byval
4 ; attribute. Check that it does. This situation can come up in LTO scenarios
5 ; where struct types end up not matching.
6
7 target triple = "i686-unknown-linux-gnu"
8
9 %struct.Foo.1 = type { i32 }
10 %struct.Foo.2 = type { i32 }
11
12 @foo = common global i32 (%struct.Foo.2*)* null, align 8
13
14 define i32 @func4(%struct.Foo.1* byval(%struct.Foo.1) %p) {
15 entry:
16 %gep = getelementptr inbounds %struct.Foo.1, %struct.Foo.1* %p, i32 0, i32 0
17 %v = load i32, i32* %gep
18 ret i32 %v
19 }
20
21 define i32 @func5(%struct.Foo.1* byval %p) {
22 entry:
23 %gep = getelementptr inbounds %struct.Foo.1, %struct.Foo.1* %p, i32 0, i32 0
24 %v = load i32, i32* %gep
25 ret i32 %v
26 }
27
28 define i32 @bar(%struct.Foo.2* %f2) {
29 entry:
30 %tmp = load i32 (%struct.Foo.2*)*, i32 (%struct.Foo.2*)** @foo, align 8
31 %call = call i32 %tmp(%struct.Foo.2* byval(%struct.Foo.2) %f2), !prof !1
32 ret i32 %call
33 }
34
35 !1 = !{!"VP", i32 0, i64 3000, i64 7651369219802541373, i64 1000, i64 3667884930908592509, i64 1000}
36
37
38 ; CHECK: define i32 @bar(%struct.Foo.2* %f2)
39 ; Cast %struct.Foo.2* to %struct.Foo.1* and use byval(%struct.Foo.2).
40 ; CHECK: %[[cast:[^ ]*]] = bitcast %struct.Foo.2* %f2 to %struct.Foo.1*
41 ; CHECK: call i32 @func4(%struct.Foo.1* byval(%struct.Foo.1) %[[cast]])
42 ; Same but when callee doesn't have explicit byval type.
43 ; CHECK: %[[cast:[^ ]*]] = bitcast %struct.Foo.2* %f2 to %struct.Foo.1*
44 ; CHECK: call i32 @func5(%struct.Foo.1* byval(%struct.Foo.1) %[[cast]])
45 ; Original call stays the same.
46 ; CHECK: call i32 %tmp(%struct.Foo.2* byval(%struct.Foo.2) %f2)