-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[Clang][OpenCL][AMDGPU] Allow _Float16 and half vector type compatibility #170605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[Clang][OpenCL][AMDGPU] Allow _Float16 and half vector type compatibility #170605
Conversation
|
@llvm/pr-subscribers-backend-amdgpu @llvm/pr-subscribers-clang Author: Rana Pratap Reddy (ranapratap55) ChangesIn OpenCL, allow implicit compatibility between Full diff: https://github.com/llvm/llvm-project/pull/170605.diff 2 Files Affected:
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index b359fc8350375..7d000f8a8764f 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -10527,6 +10527,21 @@ bool ASTContext::areCompatibleVectorTypes(QualType FirstVec,
Second->getVectorKind() != VectorKind::RVVFixedLengthMask_4)
return true;
+ // In OpenCL, treat half and _Float16 vector types as compatible.
+ if (getLangOpts().OpenCL &&
+ First->getNumElements() == Second->getNumElements()) {
+ QualType FirstElt = First->getElementType();
+ QualType SecondElt = Second->getElementType();
+
+ if ((FirstElt->isFloat16Type() && SecondElt->isHalfType()) ||
+ (FirstElt->isHalfType() && SecondElt->isFloat16Type())) {
+ if (First->getVectorKind() != VectorKind::AltiVecPixel &&
+ First->getVectorKind() != VectorKind::AltiVecBool &&
+ Second->getVectorKind() != VectorKind::AltiVecPixel &&
+ Second->getVectorKind() != VectorKind::AltiVecBool)
+ return true;
+ }
+ }
return false;
}
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index cfabd1b76c103..741bcb7e41db2 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -7819,7 +7819,8 @@ ExprResult Sema::CheckExtVectorCast(SourceRange R, QualType DestTy,
if (SrcTy->isVectorType()) {
if (!areLaxCompatibleVectorTypes(SrcTy, DestTy) ||
(getLangOpts().OpenCL &&
- !Context.hasSameUnqualifiedType(DestTy, SrcTy))) {
+ !Context.hasSameUnqualifiedType(DestTy, SrcTy) &&
+ !Context.areCompatibleVectorTypes(DestTy, SrcTy))) {
Diag(R.getBegin(),diag::err_invalid_conversion_between_ext_vectors)
<< DestTy << SrcTy << R;
return ExprError();
|
|
We will need more folks (preferably in OpenCL language committee and/or outside AMD) to review. Can you also add more context in the description? |
arsenm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing tests?
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
533b502 to
e75dd83
Compare
Added tests. |
e75dd83 to
9e31e81
Compare
wenju-he
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Summary
Allowing implicit compatibility between
_Float16vector types andhalfvector 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:
Error:
Solution
In OpenCL, allow implicit compatibility between
_Float16vector types andhalfvector types. This is needed for AMDGPU builtins that may return _Float16 vectors to work correctly with OpenCL half vector types.