KhronosGroup / SPIRV-LLVM

This project is no longer active. Please join us at
https://github.com/KhronosGroup/SPIRV-LLVM-Translator
Other
262 stars 60 forks source link

Intrinsic llvm.bswap not supported #210

Open doe300 opened 7 years ago

doe300 commented 7 years ago

Running code containing the llvm.bswap intrinsic through llvm-spirv crashes with

Fails to save LLVM as SPIRV: InvalidFunctionCall: Unexpected llvm intrinsic

According to the LLVM Language Reference, this intrinsic is used to swap the bytes in integers, e.g. to move from little-endian to big-endian and vice versa.

Since the SPIR-V specification offers no instruction to swap bytes, I guess this intrinsic should be implemented by manually shifting the single bytes in the integer numbers.

bader commented 7 years ago

So far SPIR-V translation library was used by OpenCL front-end compiler only with disabled optimizations. I suppose clang doesn't produce llvm.bswap intrinsic in this mode.

What it the environment you are using SPIR-V library in?

doe300 commented 7 years ago

So far SPIR-V translation library was used by OpenCL front-end compiler only with disabled optimizations. I suppose clang doesn't produce llvm.bswap intrinsic in this mode.

This could very well be, since I explicitly run OpenCL -> (SPIR-V-LLVM clang) -> LLVM-IR -> (llvm-spriv) -> SPIR-V so I can use optimizations -O3 in clang.

I'll try to write a pull request to support this intrinsic once #209 is through.