From a3fac27e2181df52592003021bb4a6e4c50b89eb Mon Sep 17 00:00:00 2001 From: Victor Mustya Date: Mon, 31 Oct 2022 13:27:02 -0700 Subject: =?UTF-8?q?[Backport]=20When=20creating=20a=20stack=20space=20for?= =?UTF-8?q?=20inlined=20byval=20args,=0A=20use=20the=20same=20addrspace=20?= =?UTF-8?q?as=20the=20original=20argument.?= From: Chang-Sun Lin Jr --- llvm/lib/Transforms/Utils/InlineFunction.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/llvm/lib/Transforms/Utils/InlineFunction.cpp b/llvm/lib/Transforms/Utils/InlineFunction.cpp index 792aa8208f27..6a19c53e19f8 100644 --- a/llvm/lib/Transforms/Utils/InlineFunction.cpp +++ b/llvm/lib/Transforms/Utils/InlineFunction.cpp @@ -1439,6 +1439,12 @@ static Value *HandleByValArgument(Value *Arg, Instruction *TheCall, Arg->getName(), &*Caller->begin()->begin()); IFI.StaticAllocas.push_back(cast(NewAlloca)); + // If the byval was in a different address space, add a cast. + if (DL.getAllocaAddrSpace() != ArgTy->getAddressSpace()) { + NewAlloca = new AddrSpaceCastInst( + NewAlloca, ArgTy, "", + cast(NewAlloca)->getNextNonDebugInstruction()); + } // Uses of the argument in the function should use our new alloca // instead. return NewAlloca; -- 2.34.1