Open AnastasiaStulova opened 4 years ago
Personally, I think this should be disallowed unless enabled by an extension.
Clang bug: https://bugs.llvm.org/show_bug.cgi?id=46174
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.
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.