KhronosGroup / OpenCL-Docs

OpenCL API, OpenCL C, Extensions, SPIR-V Environment Specs, Ref page, and C++ for OpenCL doc sources.
Other
359 stars 112 forks source link

Subscript in vectors #309

Open AnastasiaStulova opened 4 years ago

AnastasiaStulova commented 4 years ago

Clang allows to use subscript operator on vectors in core OpenCL mode (without any extension). The areas it can be useful is dynamic indexing: https://godbolt.org/z/8yn9LY

That can help to write more concise code using loops: https://godbolt.org/z/FMvi5v FYI for loops with static bounds LLVM can unroll the loop and change into static indexing i.e. there will be no performance loss compared to regular vector component access (see generated IR in example).

Accesses out of bounds result in undefined behavior.

Is this something we could adopt as part of the language specification, extension, etc? If else we need to change the implementation to either disallow this or make clang extension.

b-sumner commented 4 years ago

Personally, I think this should be disallowed unless enabled by an extension.

AnastasiaStulova commented 4 years ago

Clang bug: https://bugs.llvm.org/show_bug.cgi?id=46174

bashbaug commented 4 years ago

Discussed in the June 2nd teleconference.

This functionality is available in SPIR-V today, via OpVectorExtractDynamic and OpVectorInsertDynamic, so it would not require any SPIR-V changes.