LLVM-SPIRV-Backend icon indicating copy to clipboard operation
LLVM-SPIRV-Backend copied to clipboard

Support llvm memory intrinsics

Open iliya-diyachkov opened this issue 3 years ago • 2 comments

We have 5 tests with unsupported llvm memory intrinsics. The translator implements llvm.memcpy using OpCopyMemorySized memory instruction. For llvm.memmove intrinsic the translator also uses OpCopyMemorySized when memory has constant size (test memmove.ll) but it inlines the intrinsic as a loop with OpLoad/OpStore instructions for non-determined memory size, i.e. passed as a function argument (test dynamic-memmove.ll). For llvm.memset it is uses either OpCopyMemorySized or generates new functions with loops containing OpStores in the case of the initialization value is not a constant (passed as a function argument again).

llvm-intrinsics/memcpy.align.ll (llvm.memcpy* -> OpCopyMemorySized)
transcoding/spirv-private-array-initialization.ll  (llvm.memcpy* -> OpCopyMemorySized)
llvm-intrinsics/memmove.ll (llvm.memmove* -> OpCopyMemorySized)
llvm-intrinsics/dynamic-memmove.ll (llvm.memmove* -> inlined loops with OpLoad/OpStore)
llvm-intrinsics/memset.ll (llvm.memset*  -> OpCopyMemorySized or OpFunction)

I think we should start with a simple llvm.memcpy* to OpCopyMemorySized conversion, then support the loop inlining. The generation of new functions is used in the translator to support some other intrinsics (llvm.usub.sat..., llvm.fshl...), and perhaps can be implemented in the backend. But I'm not sure for now that we really need to support both inlining and the generation of new functions for llvm intrinsics support in our project.

iliya-diyachkov avatar Dec 10 '21 21:12 iliya-diyachkov

Basic support of llvm.memmove/memcpy intrinsics was added in #83. Code inlining/function generation has not been added yet. Also missed bitcasts and perhaps lifetime* intrinsics should be added to pass memcpy/memmove tests.

iliya-diyachkov avatar Dec 15 '21 09:12 iliya-diyachkov

We can handle llvm.umul.with.overflow.* (llvm-intrinsics/umul.with.overflow.ll) and llvm.fshr.*/llvm.fshl.* (llvm-intrinsics/fshr.ll, llvm-intrinsics/fshr.ll) generating new functions in SPIRVPreTranslationLegalizer.cpp.

iliya-diyachkov avatar Jun 28 '22 20:06 iliya-diyachkov