Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions lib/SPIRV/SPIRVRegularizeLLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,12 @@ void SPIRVRegularizeLLVMBase::lowerIntrinsicToFunction(
Intrinsic->setCalledFunction(F);
return;
}
// TODO copy arguments attributes: captures(none) writeonly.
FunctionCallee FC =
M->getOrInsertFunction(FuncName, Intrinsic->getFunctionType());
auto IntrinsicID = Intrinsic->getIntrinsicID();
Intrinsic->setCalledFunction(FC);

F = dyn_cast<Function>(FC.getCallee());
assert(F && "must be a function!");
F = cast<Function>(FC.getCallee());
F->setAttributes(Intrinsic->getAttributes());

switch (IntrinsicID) {
case Intrinsic::memset: {
Expand Down
31 changes: 31 additions & 0 deletions test/llvm-intrinsics/memset-param-attrs.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
; Verify that captures(none) on the @llvm.memset destination parameter is

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably also check, what LLVM IR is generated after the roundtrip, do we still have the attribute?

@aobolensk aobolensk Jul 8, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added checks

; propagated to the generated spirv.llvm_memset_* helper function, and that
; FuncParamAttr NoCapture (5) is emitted for that parameter.
;
; RUN: llvm-as %s -o %t.bc
; RUN: llvm-spirv %t.bc -spirv-text -o - | FileCheck %s --check-prefix=CHECK-SPIRV
; RUN: llvm-spirv %t.bc -o %t.spv
; RUN: llvm-spirv -r %t.spv -o %t.rev.bc
; RUN: llvm-dis < %t.rev.bc | FileCheck %s --check-prefix=CHECK-LLVM

; CHECK-SPIRV: Name [[#Helper:]] "spirv.llvm_memset_p0_i32"
; CHECK-SPIRV: Name [[#Dest:]] "dest"
; CHECK-SPIRV: Decorate [[#Dest]] FuncParamAttr 5
; CHECK-SPIRV: Function [[#]] [[#Helper]]
; CHECK-SPIRV: FunctionParameter [[#]] [[#Dest]]

; CHECK-LLVM: declare void @llvm.memset.p0.i32(ptr writeonly captures(none), i8, i32, i1 immarg)

target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-n8:16:32:64"
target triple = "spir64-unknown-unknown"

define spir_kernel void @test(ptr %dst, i8 %val, i32 %len) {
call void @llvm.memset.p0.i32(ptr captures(none) %dst, i8 %val, i32 %len, i1 false)
ret void
}

declare void @llvm.memset.p0.i32(ptr captures(none) writeonly, i8, i32, i1 immarg)

!opencl.ocl.version = !{!0}
!opencl.spir.version = !{!0}
!0 = !{i32 1, i32 0}
Loading