]> granicus.if.org Git - clang/commitdiff
The comparison of two vectors should return a signed result. hasIntegerRepresentation...
authorTanya Lattner <tonic@nondot.org>
Mon, 17 Oct 2011 21:00:38 +0000 (21:00 +0000)
committerTanya Lattner <tonic@nondot.org>
Mon, 17 Oct 2011 21:00:38 +0000 (21:00 +0000)
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.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142250 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/CodeGen/ext-vector.c
test/Sema/vector-ops.c
test/SemaOpenCL/vec_compare.cl [new file with mode: 0644]

index 346228f6b7b30b00edbc08fc6bbc6d57fedcf1b5..d3dec96d44cbca47c8ece3048c86ce2235824068 100644 (file)
@@ -6760,19 +6760,19 @@ QualType Sema::CheckVectorCompareOperands(ExprResult &LHS, ExprResult &RHS,
     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());
index a222f9445e089388c9a499a669754b3654b084f9..896814bc24ad3322ad3e370b0af9b38e9ab1dfca 100644 (file)
@@ -252,7 +252,8 @@ int4 test13(int4 *V) {
 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 @@ void test14(uint4 *ap, uint4 *bp, unsigned c) {
   // 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;
 }
index ca397375d73921a59dc7a87c22a2f9545821fe79..c3f84aae40af0fa3990221b9603834646b6570a7 100644 (file)
@@ -13,8 +13,9 @@ void test1(v2u v2ua, v2s v2sa, v2f v2fa) {
   (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];
diff --git a/test/SemaOpenCL/vec_compare.cl b/test/SemaOpenCL/vec_compare.cl
new file mode 100644 (file)
index 0000000..dd91aa5
--- /dev/null
@@ -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;
+}
+