[cfe-dev] [PATCH] [OpenCL] Conversions for ternary operations between scalar and vector

Colin Riddell colinriddell at codeplay.com
Wed Dec 10 07:56:45 PST 2014


> Also my mistake about the error not showing up. The actual example 
> that I tried was "float2 = char2 ? float : float". Attached the 
> modified copy that I had created from your original lit test. This 
> requires your patch to avoid the assertion. I believe this assignment 
> should not cause any error at all.
Agreed, and thanks for the test. Added that to the patch.

> we first promote LHS or RHS (but never both) to the "resulting 
> matching type", and then expand them to vectors that match the 
> condition type.
I think we are on the same track. I was not talking about promoting both 
LHS and RHS, just one of them.

It's worth pointing out that the select generation is handled in 
CGExprScalar.cpp Value *ScalarExprEmitter::
VisitAbstractConditionalOperator()

Attached is another patch for review, including both tests. Now ignore 
the first patch I submitted. This new change passes all the tests run 
with check-clang.

Regards,
Colin

-- 
Colin Riddell

Team Lead - GPGPU Software Systems

Codeplay Software Ltd
45 York Place, Edinburgh, EH1 3HP
Tel: 0131 466 0503
Fax: 0131 557 6600
Website: http://www.codeplay.com

This email and any attachments may contain confidential and /or privileged information and  is for use  by the addressee only. If you are not the intended recipient, please notify Codeplay Software Ltd immediately and delete the message from your computer. You may not copy or forward it,or use or disclose its contents to any other person. Any views or other information in this message which do not relate to our business are not authorized by Codeplay software Ltd, nor does this message form part of any contract unless so stated.
As internet communications are capable of data corruption Codeplay Software Ltd does not accept any responsibility for any changes made to this message after it was sent. Please note that Codeplay Software Ltd does not accept any liability or responsibility for viruses and it is your responsibility to scan any attachments.
Company registered in England and Wales, number: 04567874
Registered office: 81 Linkfield Street, Redhill RH1 6BY

-------------- next part --------------
diff --git a/test/SemaOpenCL/vector_ternary_cast.cl b/test/SemaOpenCL/vector_ternary_cast.cl
new file mode 100644
index 0000000..fc4a5f3
--- /dev/null
+++ b/test/SemaOpenCL/vector_ternary_cast.cl
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+// expected-no-diagnostics
+
+typedef char char2 __attribute__((ext_vector_type(2)));
+typedef char char3 __attribute__((ext_vector_type(3)));
+typedef char char4 __attribute__((ext_vector_type(4)));
+typedef char char8 __attribute__((ext_vector_type(8)));
+typedef char char16 __attribute__((ext_vector_type(16)));
+
+__kernel void test(__global char *srcA, __global char *srcB, __global char2 *srcC, __global char2 *dst)
+{
+  int  tid = 1;
+
+  char valA = srcA[ tid ];
+  char valB = srcB[ tid ];
+  char2 valC = srcC[ tid ];
+  char2 destVal = valC ? valA : valB;
+  dst[ tid ] = destVal;
+}
+
diff --git a/test/SemaOpenCL/vector_ternary_cast2.cl b/test/SemaOpenCL/vector_ternary_cast2.cl
new file mode 100644
index 0000000..3bd636f
--- /dev/null
+++ b/test/SemaOpenCL/vector_ternary_cast2.cl
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 %s -x cl -verify -pedantic -fsyntax-only
+// expected-no-diagnostics
+
+typedef char char2 __attribute__((ext_vector_type(2)));
+typedef char char3 __attribute__((ext_vector_type(3)));
+typedef char char4 __attribute__((ext_vector_type(4)));
+typedef char char8 __attribute__((ext_vector_type(8)));
+typedef char char16 __attribute__((ext_vector_type(16)));
+
+typedef float float2 __attribute__((ext_vector_type(2)));
+
+__kernel void test(__global float *srcA, __global float *srcB, __global char2 *srcC, __global float2 *dst)
+{
+  int  tid = 1;
+
+  float valA = srcA[ tid ];
+  float valB = srcB[ tid ];
+  char2 valC = srcC[ tid ];
+  float2 destVal = valC ? valA : valB;
+  dst[ tid ] = destVal;
+}
+
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 76e3612..14bc264 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -5822,8 +5822,8 @@ QualType Sema::CheckConditionalOperands(ExprResult &Cond, ExprResult &LHS,
   // If the condition is a vector, and both operands are scalar,
   // attempt to implicity convert them to the vector type to act like the
   // built in select. (OpenCL v1.1 s6.3.i)
-  if (getLangOpts().OpenCL && CondTy->isVectorType())
-    if (checkConditionalConvertScalarsToVectors(*this, LHS, RHS, CondTy))
+  if (getLangOpts().OpenCL && ResTy->isVectorType())
+    if (checkConditionalConvertScalarsToVectors(*this, LHS, RHS, ResTy))
       return QualType();
   
   // If both operands have arithmetic type, do the usual arithmetic conversions


More information about the cfe-dev mailing list