On Tue, Dec 29, 2020 at 8:19 PM Alexander Monakov <amona...@ispras.ru> wrote: > > On Tue, 29 Dec 2020, Richard Biener via Gcc wrote: > > > >I think clang follows gcc and uses the type of the first operand. > > > > The desired behavior is the one that OpenCL specifies. If it is > > implementation > > defined we should document behavior. I agree symmetry is nice but eventually > > the current C behavior is what OpenCL specifies. > > Where does OpenCL specify that? Checking the 1.2 OpenCL standard I see the > opposite (the code would fail to compile): > > 6.2.1 > Implicit Conversions > > [...] > > Implicit conversions between built-in vector data types are disallowed.
But then in 6.4 it says operations operate component-wise not saying anything about type requirements ... which suggests that int4 i; uint4 u; i = i + u; is valid and is implemented as in C i.x = i.x + u.x; i.y = i.y + u.y; ... and C then doing the appropriate implicit conversions. So yes, OpenCL doesn't specify implicit conversions and 6.4 suggests that components are promoted as to C rules which means the current C implementation matches neither. Note changing the C frontend can change operation outcome. IIRC we at some point decided to allow implicit sign conversions (we don't implement convert_VECTOR_TYPE nor clangs convert_vector). Richard. > Alexander