[PATCH] D101519: [C++4OpenCL] Fix reinterpret_cast of vectors

Anastasia Stulova via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon May 10 05:15:28 PDT 2021


Anastasia added inline comments.


================
Comment at: clang/test/SemaOpenCLCXX/reinterpret-cast.clcpp:15
+  int4 i4;
+  auto i4_to_i3 = reinterpret_cast<int3>(i4); // expected-error{{reinterpret_cast from vector 'int4' (vector of 4 'int' values) to vector 'int3' (vector of 3 'int' values) of different size}}
+
----------------
I think in OpenCL vector 3 should be setup as vector 4 in memory with the 4th component being `undef` value. So this conversion should be permitted.

For example you can reinterpret cast between 3 and 4 components vectors using as_typen functions.

https://godbolt.org/z/sKqnYhnGe

I don't think we have a comprehensive description but these are the quotes from OpenCL C:

>For 3-component vector data types, the size of the data type is 4 * sizeof(component). This means that a 3-component vector data type will be aligned to a 4 * sizeof(component) boundary. The vload3 and vstore3 built-in functions can be used to read and write, respectively, 3-component vector data types from an array of packed scalar data type.

> When the operand and result type contain a different number of elements, the result shall be implementation-defined except if the operand is a 4-component vector and the result is a 3-component vector. In this case, the bits in the operand shall be returned directly without modification as the new type. 

> The suffixes .lo (or .even) and .hi (or .odd) for a 3-component vector type operate as if the 3-component vector type is a 4-component vector type with the value in the w component undefined.




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D101519/new/

https://reviews.llvm.org/D101519



More information about the cfe-commits mailing list