llvm.org GIT mirror llvm / 92938b7
we don't have to make an explicit copy of a byval argument when inlining a function if we know that the function does not write to *any* memory. This implements test/Transforms/Inline/byval2.ll git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@45912 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 11 years ago
2 changed file(s) with 34 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
240240 Value *ActualArg = *AI;
241241
242242 // When byval arguments actually inlined, we need to make the copy implied
243 // by them actually explicit.
244 // TODO: If we know that the callee never modifies the struct, we can
245 // remove this copy.
246 if (CalledFunc->paramHasAttr(ArgNo+1, ParamAttr::ByVal)) {
243 // by them explicit. However, we don't do this if the callee is readonly
244 // or readnone, because the copy would be unneeded: the callee doesn't
245 // modify the struct.
246 if (CalledFunc->paramHasAttr(ArgNo+1, ParamAttr::ByVal) &&
247 !CalledFunc->paramHasAttr(0, ParamAttr::ReadOnly) &&
248 !CalledFunc->paramHasAttr(0, ParamAttr::ReadNone)) {
247249 const Type *AggTy = cast(I->getType())->getElementType();
248250 const Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty);
249251
0 ; RUN: llvm-as < %s | opt -inline | llvm-dis | not grep {llvm.memcpy}
1
2 ; Inlining a byval struct should NOT cause an explicit copy
3 ; into an alloca if the function is readonly
4
5 %struct.ss = type { i32, i64 }
6 @.str = internal constant [10 x i8] c"%d, %lld\0A\00" ; <[10 x i8]*> [#uses=1]
7
8 define internal i32 @f(%struct.ss* byval %b) nounwind readonly {
9 entry:
10 %tmp = getelementptr %struct.ss* %b, i32 0, i32 0 ; [#uses=2]
11 %tmp1 = load i32* %tmp, align 4 ; [#uses=1]
12 %tmp2 = add i32 %tmp1, 1 ; [#uses=1]
13 ret i32 %tmp2
14 }
15
16 declare i32 @printf(i8*, ...) nounwind
17
18 define i32 @main() nounwind {
19 entry:
20 %S = alloca %struct.ss ; <%struct.ss*> [#uses=4]
21 %tmp1 = getelementptr %struct.ss* %S, i32 0, i32 0 ; [#uses=1]
22 store i32 1, i32* %tmp1, align 8
23 %tmp4 = getelementptr %struct.ss* %S, i32 0, i32 1 ; [#uses=1]
24 store i64 2, i64* %tmp4, align 4
25 %X = call i32 @f( %struct.ss* byval %S ) nounwind
26 ret i32 %X
27 }