diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -3395,6 +3395,10 @@ if (CallerPAL.hasParamAttr(i, Attribute::SwiftError)) return false; + if (!CallerPAL.hasParamAttr(i, Attribute::ByVal) && + Callee->getAttributes().hasParamAttr(i, Attribute::ByVal)) + return false; // Cannot transform to byval. + // If the parameter is passed as a byval argument, then we have to have a // sized type and the sized type has to have the same size as the old type. if (ParamTy != ActTy && CallerPAL.hasParamAttr(i, Attribute::ByVal)) { diff --git a/llvm/test/Transforms/InstCombine/cast-to-byval.ll b/llvm/test/Transforms/InstCombine/cast-to-byval.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Transforms/InstCombine/cast-to-byval.ll @@ -0,0 +1,14 @@ +; Check that function calls involving conversion to byval aren't transformed. +; RUN: opt < %s -passes=instcombine -S | FileCheck %s + +define i32 @bar(i32 %0) { + %2 = tail call i32 @foo(i32 %0) +; CHECK: %2 = tail call i32 @foo(i32 %0) + ret i32 %2 +} + +%Foo = type { i32 } +define i32 @foo (ptr byval(%Foo) %foo) { + %1 = load i32, ptr %foo, align 4 + ret i32 %1 +}