Author: baldrick Date: Sun Jan 27 12:12:58 2008 New Revision: 46416 URL: http://llvm.org/viewvc/llvm-project?rev=46416&view=rev Log: Revert r46393: readonly/readnone functions are no longer allowed to write through byval arguments.
Modified: llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp llvm/trunk/test/Transforms/Inline/byval2.ll Modified: llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp?rev=46416&r1=46415&r2=46416&view=diff ============================================================================== --- llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp (original) +++ llvm/trunk/lib/Transforms/Utils/InlineFunction.cpp Sun Jan 27 12:12:58 2008 @@ -240,15 +240,12 @@ E = CalledFunc->arg_end(); I != E; ++I, ++AI, ++ArgNo) { Value *ActualArg = *AI; - // When byval arguments are inlined, we need to make the copy implied - // by them explicit. It is tempting to think that this is not needed if - // the callee is readonly, because the callee doesn't modify the struct. - // However this would be wrong: readonly means that any writes the callee - // performs are not visible to the caller. But writes by the callee to - // an argument passed byval are by definition not visible to the caller! - // Since we allow this kind of readonly function, there needs to be an - // explicit copy in order to keep the writes invisible after inlining. - if (CalledFunc->paramHasAttr(ArgNo+1, ParamAttr::ByVal)) { + // When byval arguments actually inlined, we need to make the copy implied + // by them explicit. However, we don't do this if the callee is readonly + // or readnone, because the copy would be unneeded: the callee doesn't + // modify the struct. + if (CalledFunc->paramHasAttr(ArgNo+1, ParamAttr::ByVal) && + !CalledFunc->onlyReadsMemory()) { const Type *AggTy = cast<PointerType>(I->getType())->getElementType(); const Type *VoidPtrTy = PointerType::getUnqual(Type::Int8Ty); Modified: llvm/trunk/test/Transforms/Inline/byval2.ll URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/Inline/byval2.ll?rev=46416&r1=46415&r2=46416&view=diff ============================================================================== --- llvm/trunk/test/Transforms/Inline/byval2.ll (original) +++ llvm/trunk/test/Transforms/Inline/byval2.ll Sun Jan 27 12:12:58 2008 @@ -1,7 +1,7 @@ -; RUN: llvm-as < %s | opt -inline | llvm-dis | grep {llvm.memcpy} +; RUN: llvm-as < %s | opt -inline | llvm-dis | not grep {llvm.memcpy} -; Inlining a byval struct should cause an explicit copy -; into an alloca even if the function is readonly +; Inlining a byval struct should NOT cause an explicit copy +; into an alloca if the function is readonly %struct.ss = type { i32, i64 } @.str = internal constant [10 x i8] c"%d, %lld\0A\00" ; <[10 x i8]*> [#uses=1] _______________________________________________ llvm-commits mailing list llvm-commits@cs.uiuc.edu http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits