From 29778b0567d8916d7914daaa358991eb0bb2fa52 Mon Sep 17 00:00:00 2001 From: bmanga Date: Tue, 14 May 2024 20:39:42 +0100 Subject: [PATCH] Do not copy immarg attribute in LowerAddrSpaceCast --- lib/LowerAddrSpaceCastPass.cpp | 6 ++++++ test/AddressSpaceCast/issue-1350.ll | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 test/AddressSpaceCast/issue-1350.ll diff --git a/lib/LowerAddrSpaceCastPass.cpp b/lib/LowerAddrSpaceCastPass.cpp index aa3c5c403..2e497b578 100644 --- a/lib/LowerAddrSpaceCastPass.cpp +++ b/lib/LowerAddrSpaceCastPass.cpp @@ -283,6 +283,12 @@ llvm::Value *clspv::LowerAddrSpaceCastPass::visitCallInst(llvm::CallInst &I) { }; Function *EquivalentFunction = getEquivalentFunction(); EquivalentFunction->copyAttributesFrom(F); + + // When creating intrinsics equivalents (eg. llvm.memcpy.*), we must drop + // attributes that cannot be applied to non-intrinsics. + for (auto i = 0u; i < EquivalentFunction->arg_size(); ++i) { + EquivalentFunction->removeParamAttr(i, Attribute::ImmArg); + } EquivalentFunction->setCallingConv(F->getCallingConv()); IRBuilder<> B(&I); diff --git a/test/AddressSpaceCast/issue-1350.ll b/test/AddressSpaceCast/issue-1350.ll new file mode 100644 index 000000000..8eef938cd --- /dev/null +++ b/test/AddressSpaceCast/issue-1350.ll @@ -0,0 +1,23 @@ +; RUN: clspv-opt %s -o %t.ll --passes=lower-addrspacecast +; RUN: FileCheck %s < %t.ll + +; CHECK: declare void @_Z21llvm.memcpy.p0.p4.i32PPU3AS1memcpy.p0.p4.i32(ptr noalias nocapture writeonly, ptr addrspace(1) noalias nocapture readonly, i32, i1) #0 + +; CHECK-NOT: addrspacecast +; CHECK-NOT: @llvm.memcpy.p0.p4.i32 + +target datalayout = "e-p:32:32-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024" +target triple = "spir-unknown-unknown" + +define dso_local spir_kernel void @kern(ptr addrspace(1) align 4 %in) { +entry: + %cpy = alloca [4 x float], align 4 + %0 = addrspacecast ptr addrspace(1) %in to ptr addrspace(4) + call void @llvm.memcpy.p0.p4.i32(ptr align 4 %cpy, ptr addrspace(4) align 4 %0, i32 16, i1 false) + ret void +} + +; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: readwrite) +declare void @llvm.memcpy.p0.p4.i32(ptr noalias nocapture writeonly, ptr addrspace(4) noalias nocapture readonly, i32, i1 immarg) #0 + +attributes #0 = { nocallback nofree nounwind willreturn memory(argmem: readwrite) } \ No newline at end of file