https://github.com/ranapratap55 created 
https://github.com/llvm/llvm-project/pull/170605

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.

>From a5e80021e033797a81d8acf3048c46f369291664 Mon Sep 17 00:00:00 2001
From: ranapratap55 <[email protected]>
Date: Thu, 4 Dec 2025 11:35:32 +0530
Subject: [PATCH] [Clang][OpenCL][AMDGPU] Allow _Float16 and half vector type
 compatability

---
 clang/lib/AST/ASTContext.cpp | 15 +++++++++++++++
 clang/lib/Sema/SemaExpr.cpp  |  3 ++-
 2 files changed, 17 insertions(+), 1 deletion(-)

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();

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to