Skip to content

Commit cff4602

Browse files
committed
[AMDGPU] Treating HIP/C++ _Float16 same as OpenCL's half
1 parent 1c42262 commit cff4602

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

clang/lib/AST/ASTContext.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10527,6 +10527,21 @@ bool ASTContext::areCompatibleVectorTypes(QualType FirstVec,
1052710527
Second->getVectorKind() != VectorKind::RVVFixedLengthMask_4)
1052810528
return true;
1052910529

10530+
// In OpenCL, treat half and _Float16 vector types as compatible.
10531+
if (getLangOpts().OpenCL &&
10532+
First->getNumElements() == Second->getNumElements()) {
10533+
QualType FirstElt = First->getElementType();
10534+
QualType SecondElt = Second->getElementType();
10535+
10536+
if ((FirstElt->isFloat16Type() && SecondElt->isHalfType()) ||
10537+
(FirstElt->isHalfType() && SecondElt->isFloat16Type())) {
10538+
if (First->getVectorKind() != VectorKind::AltiVecPixel &&
10539+
First->getVectorKind() != VectorKind::AltiVecBool &&
10540+
Second->getVectorKind() != VectorKind::AltiVecPixel &&
10541+
Second->getVectorKind() != VectorKind::AltiVecBool)
10542+
return true;
10543+
}
10544+
}
1053010545
return false;
1053110546
}
1053210547

clang/test/SemaOpenCL/builtins-extended-image-param-gfx1100-err.cl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
typedef int int4 __attribute__((ext_vector_type(4)));
77
typedef float float4 __attribute__((ext_vector_type(4)));
8-
typedef _Float16 half4 __attribute__((ext_vector_type(4)));
8+
typedef half half4 __attribute__((ext_vector_type(4)));
99

1010
float4 test_amdgcn_image_gather4_lz_2d_v4f32_f32_r(float4 v4f32, float f32, int i32, __amdgpu_texture_t tex, int4 vec4i32) {
1111

clang/test/SemaOpenCL/builtins-extended-image-param-gfx942-err.cl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
typedef int int4 __attribute__((ext_vector_type(4)));
77
typedef float float4 __attribute__((ext_vector_type(4)));
8-
typedef _Float16 half4 __attribute__((ext_vector_type(4)));
8+
typedef half half4 __attribute__((ext_vector_type(4)));
99

1010
float4 test_amdgcn_image_gather4_lz_2d_v4f32_f32_r(float4 v4f32, float f32, int i32, __amdgpu_texture_t tex, int4 vec4i32) {
1111

0 commit comments

Comments
 (0)