You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Clang][OpenCL][AMDGPU] Allow _Float16 and half vector type compatibility (#170605)
## Summary
Allowing implicit compatibility between `_Float16` vector types and
`half` vector types in OpenCL mode. This enables AMDGPU builtins to work
correctly across OpenCL, HIP, and C++ without requiring separate builtin
definitions.
## Problem Statement
When using AMDGPU image builtins that return half-precision vectors in
OpenCL, users encounter type incompatibility errors:
**Builtin Definition:**
`TARGET_BUILTIN(__builtin_amdgcn_image_load_1d_v4f16_i32, "V4xiiQtii",
"nc", "image-insts")`
**Test Case:**
```
typedef half half4 __attribute__((ext_vector_type(4)));
half4 test_builtin_image_load_1d_2(half4 v4f16, int i32, __amdgpu_texture_t tex) {
return __builtin_amdgcn_image_load_1d_v4f16_i32(100, i32, tex, 120, i32);
}
```
**Error:**
```
error: returning '__attribute__((__vector_size__(4 * sizeof(_Float16)))) _Float16'
(vector of 4 '_Float16' values) from a function with incompatible result type
'half4' (vector of 4 'half' values)
```
## Solution
In OpenCL, allow implicit compatibility between `_Float16` vector types
and `half` vector types. This is needed for AMDGPU builtins that may
return _Float16 vectors to work correctly with OpenCL half vector types.
half2h2=f16_3 ; // expected-error{{initializing '__private half2' (vector of 2 'half' values) with an expression of incompatible type '__private float16_3' (vector of 3 '_Float16' values)}}
63
+
half3h3=f16_2; // expected-error{{initializing '__private half3' (vector of 3 'half' values) with an expression of incompatible type '__private float16_2' (vector of 2 '_Float16' values)}}
64
+
half4h4=f16_8; // expected-error{{initializing '__private half4' (vector of 4 'half' values) with an expression of incompatible type '__private float16_8' (vector of 8 '_Float16' values)}}
65
+
half8h8=f16_4; // expected-error{{initializing '__private half8' (vector of 8 'half' values) with an expression of incompatible type '__private float16_4' (vector of 4 '_Float16' values)}}
66
+
half16h16=f16_4; // expected-error{{initializing '__private half16' (vector of 16 'half' values) with an expression of incompatible type '__private float16_4' (vector of 4 '_Float16' values)}}
float16_2f16_2=h3; // expected-error{{initializing '__private float16_2' (vector of 2 '_Float16' values) with an expression of incompatible type '__private half3' (vector of 3 'half' values)}}
71
+
float16_3f16_3=h2; // expected-error{{initializing '__private float16_3' (vector of 3 '_Float16' values) with an expression of incompatible type '__private half2' (vector of 2 'half' values)}}
72
+
float16_4f16_4=h8; // expected-error{{initializing '__private float16_4' (vector of 4 '_Float16' values) with an expression of incompatible type '__private half8' (vector of 8 'half' values)}}
73
+
float16_8f16_8=h4; // expected-error{{initializing '__private float16_8' (vector of 8 '_Float16' values) with an expression of incompatible type '__private half4' (vector of 4 'half' values)}}
74
+
float16_16f16_16=h4; // expected-error{{initializing '__private float16_16' (vector of 16 '_Float16' values) with an expression of incompatible type '__private half4' (vector of 4 'half' values)}}
0 commit comments