KhronosGroup / KhronosGroup/SPIRV-LLVM-Translator
An issue with llvm.memset intrinsic
- Dominant language
- LLVM
- Stars
- 625
- Forks
- 279
- Avg merge
- 3d 5h
- Merged PRs (30d)
- 34
Description
The following LLVM 16 bitcode:
```llvm
; ModuleID = 'from-llvm-16.cl'
source_filename = "from-llvm-16.cl"
target datalayout = "e-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024"
target triple = "spirv64"
; Function Attrs: nofree norecurse nosync nounwind memory(argmem: write)
define spir_kernel void @k(ptr addrspace(1) nocapture noundef writeonly align 1 %0, i8 noundef signext %1) local_unnamed_addr #0 !kernel_arg_addr_space !4 !kernel_arg_access_qual !5 !kernel_arg_type !6 !kernel_arg_base_type !6 !kernel_arg_type_qual !7 {
tail call void @llvm.memset.p1.i64(ptr addrspace(1) noundef align 1 dereferenceable(123) %0, i8 %1, i64 123, i1 false), !tbaa !8
ret void
}
; Function Attrs: nocallback nofree nounwind willreturn memory(argmem: write)
declare void @llvm.memset.p1.i64(ptr addrspace(1) nocapture writeonly, i8, i64, i1 immarg) #1
attributes #0 = { nofree norecurse nosync nounwind memory(argmem: write) "frame-pointer"="all" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "uniform-work-group-size"="true" }
attributes #1 = { nocallback nofree nounwind willreturn memory(argmem: write) }
!llvm.module.flags = !{!0, !1}
!opencl.ocl.version = !{!2}
!llvm.ident = !{!3}
!0 = !{i32 1, !"wchar_size", i32 4}
!1 = !{i32 7, !"frame-pointer", i32 2}
!2 = !{i32 1, i32 2}
!3 = !{!"Ubuntu clang version 16.0.6 (++20230710042027+7cbf1a259152-1~exp1~20230710162048.105)"}
!4 = !{i32 1, i32 0}
!5 = !{!"none", !"none"}
!6 = !{!"char*", !"char"}
!7 = !{!"", !""}
!8 = !{!9, !9, i64 0}
!9 = !{!"omnipotent char", !10, i64 0}
!10 = !{!"Simple C/C++ TBAA"}
```
... translates to SPIR-V (with locally built llvm-spirv for LLVM 16) but reverse translation fails at least with llvm-spirv for LLVM 15 (provided by APT in Ubuntu 22.04):
```
$ llvm-as-16 from-llvm-16.ll -o - | llvm-spirv-16 -o from-llvm-16.spv
$ llvm-spirv-15 -r from-llvm-16.spv -o to-llvm-15.bc
Fails to verify module: Intrinsic name not mangled correctly for type arguments! Should be: llvm.memset.p1i8.i64
void (i8 addrspace(1)*, i8, i64, i1)* @llvm.memset.p1.i64
```
Contributor guide
Research direction
Start with the reproduced commands using from-llvm-16.ll, llvm-spirv-16, and llvm-spirv-15, then inspect the reverse-translation handling of llvm.memset.p1.i64. The work is complete when the provided SPIR-V round-trips through llvm-spirv-15 without the intrinsic mangling verification failure.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100