[cfe-commits] r142250 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/CodeGen/ext-vector.c test/Sema/vector-ops.c test/SemaOpenCL/vec_compare.cl

Tanya Lattner tonic at nondot.org
Mon Oct 17 14:00:38 PDT 2011


Author: tbrethou
Date: Mon Oct 17 16:00:38 2011
New Revision: 142250

URL: http://llvm.org/viewvc/llvm-project?rev=142250&view=rev
Log:
The comparison of two vectors should return a signed result. hasIntegerRepresentation() used to always return false for vectors, but since it was changed, it also
changed the return type of a compare of two unsigned vectors to be unsigned. This patch removes the check for hasIntegerRepresentation since its not needed and returns the appropriate signed type.
I added a new test case and updated exisiting test cases that assumed an unsigned result.

Added:
    cfe/trunk/test/SemaOpenCL/vec_compare.cl
Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/CodeGen/ext-vector.c
    cfe/trunk/test/Sema/vector-ops.c

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=142250&r1=142249&r2=142250&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Oct 17 16:00:38 2011
@@ -6760,19 +6760,19 @@
     CheckFloatComparison(Loc, LHS.get(), RHS.get());
   }
 
-  // Return the type for the comparison, which is the same as vector type for
-  // integer vectors, or an integer type of identical size and number of
-  // elements for floating point vectors.
-  if (LHSType->hasIntegerRepresentation())
-    return LHSType;
-
+  // Return a signed type that is of identical size and number of elements.
+  // For floating point vectors, return an integer type of identical size 
+  // and number of elements.
   const VectorType *VTy = LHSType->getAs<VectorType>();
   unsigned TypeSize = Context.getTypeSize(VTy->getElementType());
-  if (TypeSize == Context.getTypeSize(Context.IntTy))
+  if (TypeSize == Context.getTypeSize(Context.CharTy))
+    return Context.getExtVectorType(Context.CharTy, VTy->getNumElements());
+  else if (TypeSize == Context.getTypeSize(Context.ShortTy))
+    return Context.getExtVectorType(Context.ShortTy, VTy->getNumElements());
+  else if (TypeSize == Context.getTypeSize(Context.IntTy))
     return Context.getExtVectorType(Context.IntTy, VTy->getNumElements());
-  if (TypeSize == Context.getTypeSize(Context.LongTy))
+  else if (TypeSize == Context.getTypeSize(Context.LongTy))
     return Context.getExtVectorType(Context.LongTy, VTy->getNumElements());
-
   assert(TypeSize == Context.getTypeSize(Context.LongLongTy) &&
          "Unhandled vector element size in vector compare");
   return Context.getExtVectorType(Context.LongLongTy, VTy->getNumElements());

Modified: cfe/trunk/test/CodeGen/ext-vector.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/ext-vector.c?rev=142250&r1=142249&r2=142250&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/ext-vector.c (original)
+++ cfe/trunk/test/CodeGen/ext-vector.c Mon Oct 17 16:00:38 2011
@@ -252,7 +252,8 @@
 void test14(uint4 *ap, uint4 *bp, unsigned c) {
   uint4 a = *ap;
   uint4 b = *bp;
-
+  int4 d;
+  
   // CHECK: udiv <4 x i32>
   // CHECK: urem <4 x i32>
   a = a / b;
@@ -269,10 +270,10 @@
   // CHECK: icmp uge
   // CHECK: icmp eq
   // CHECK: icmp ne
-  a = a < b;
-  a = a <= b;
-  a = a > b;
-  a = a >= b;
-  a = a == b;
-  a = a != b;
+  d = a < b;
+  d = a <= b;
+  d = a > b;
+  d = a >= b;
+  d = a == b;
+  d = a != b;
 }

Modified: cfe/trunk/test/Sema/vector-ops.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/vector-ops.c?rev=142250&r1=142249&r2=142250&view=diff
==============================================================================
--- cfe/trunk/test/Sema/vector-ops.c (original)
+++ cfe/trunk/test/Sema/vector-ops.c Mon Oct 17 16:00:38 2011
@@ -13,8 +13,9 @@
   (void)(~v2fa); // expected-error{{invalid argument type 'v2f' to unary}}
 
   // Comparison operators
-  v2ua = (v2ua==v2sa);
-
+  v2ua = (v2ua==v2sa); // expected-warning{{incompatible vector types assigning to 'v2u' from 'int  __attribute__((ext_vector_type(2)))'}}
+  v2sa = (v2ua==v2sa);
+  
   // Arrays
   int array1[v2ua]; // expected-error{{size of array has non-integer type 'v2u'}}
   int array2[17];

Added: cfe/trunk/test/SemaOpenCL/vec_compare.cl
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaOpenCL/vec_compare.cl?rev=142250&view=auto
==============================================================================
--- cfe/trunk/test/SemaOpenCL/vec_compare.cl (added)
+++ cfe/trunk/test/SemaOpenCL/vec_compare.cl Mon Oct 17 16:00:38 2011
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 %s -verify -pedantic -fsyntax-only
+
+typedef __attribute__((ext_vector_type(2)))  unsigned int uint2;
+typedef __attribute__((ext_vector_type(2)))  int int2;
+
+void unsignedCompareOps()
+{
+  uint2 A, B;
+  int2 result = A != B;
+}
+





More information about the cfe-commits mailing list