[PATCH] D19123: In vector comparisons, handle scalar LHS just as we handle scalar RHS
Reid Kleckner via cfe-commits
cfe-commits at lists.llvm.org
Thu Apr 14 14:09:13 PDT 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL266366: In vector comparisons, handle scalar LHS just as we handle scalar RHS (authored by rnk).
Changed prior to commit:
http://reviews.llvm.org/D19123?vs=53745&id=53782#toc
Repository:
rL LLVM
http://reviews.llvm.org/D19123
Files:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/CodeGen/vector.c
cfe/trunk/test/Sema/vector-cast.c
Index: cfe/trunk/test/CodeGen/vector.c
===================================================================
--- cfe/trunk/test/CodeGen/vector.c
+++ cfe/trunk/test/CodeGen/vector.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple i386-apple-darwin9 -O1 -target-cpu pentium4 -target-feature +sse4.1 -debug-info-kind=limited -emit-llvm %s -o - | FileCheck %s
+// RUN: %clang_cc1 -triple i386-apple-darwin9 -O1 -target-cpu core2 -debug-info-kind=limited -emit-llvm %s -o - | FileCheck %s
typedef short __v4hi __attribute__ ((__vector_size__ (8)));
void test1() {
@@ -62,3 +62,23 @@
extern __typeof(_mm_extract_epi16(_mm_setzero_si128(), 3)) check_result_int;
extern __typeof(_mm_extract_epi32(_mm_setzero_si128(), 3)) check_result_int;
}
+
+// Test some logic around our lax vector comparison rules with integers.
+
+typedef int vec_int1 __attribute__((vector_size(4)));
+vec_int1 lax_vector_compare1(int x, vec_int1 y) {
+ y = x == y;
+ return y;
+}
+
+// CHECK: define i32 @lax_vector_compare1(i32 {{.*}}, i32 {{.*}})
+// CHECK: icmp eq <1 x i32>
+
+typedef int vec_int2 __attribute__((vector_size(8)));
+vec_int2 lax_vector_compare2(long long x, vec_int2 y) {
+ y = x == y;
+ return y;
+}
+
+// CHECK: define void @lax_vector_compare2(<2 x i32>* {{.*sret.*}}, i64 {{.*}}, i64 {{.*}})
+// CHECK: icmp eq <2 x i32>
Index: cfe/trunk/test/Sema/vector-cast.c
===================================================================
--- cfe/trunk/test/Sema/vector-cast.c
+++ cfe/trunk/test/Sema/vector-cast.c
@@ -50,7 +50,12 @@
float2 f2;
double d;
f2 += d;
- d += f2;
+ // We used to allow the next statement, but we've always rejected the next two
+ // statements
+ // FIXME: This diagnostic is inaccurate.
+ d += f2; // expected-error {{cannot convert between vector values of different size}}
+ d = f2; // expected-error {{assigning to 'double' from incompatible type 'float2'}}
+ d = d + f2; // expected-error {{assigning to 'double' from incompatible type 'float2'}}
}
// rdar://15931426
Index: cfe/trunk/lib/Sema/SemaExpr.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp
+++ cfe/trunk/lib/Sema/SemaExpr.cpp
@@ -7929,14 +7929,16 @@
return RHSType;
}
- // If we're allowing lax vector conversions, only the total (data) size
- // needs to be the same.
- // FIXME: Should we really be allowing this?
- // FIXME: We really just pick the LHS type arbitrarily?
- if (isLaxVectorConversion(RHSType, LHSType)) {
- QualType resultType = LHSType;
- RHS = ImpCastExprToType(RHS.get(), resultType, CK_BitCast);
- return resultType;
+ // If we're allowing lax vector conversions, only the total (data) size needs
+ // to be the same. If one of the types is scalar, the result is always the
+ // vector type. Don't allow this if the scalar operand is an lvalue.
+ QualType VecType = LHSVecType ? LHSType : RHSType;
+ QualType ScalarType = LHSVecType ? RHSType : LHSType;
+ ExprResult *ScalarExpr = LHSVecType ? &RHS : &LHS;
+ if (isLaxVectorConversion(ScalarType, VecType) &&
+ !ScalarExpr->get()->isLValue()) {
+ *ScalarExpr = ImpCastExprToType(ScalarExpr->get(), VecType, CK_BitCast);
+ return VecType;
}
// Okay, the expression is invalid.
@@ -9480,7 +9482,7 @@
}
// Return a signed type for the vector.
- return GetSignedVectorType(LHSType);
+ return GetSignedVectorType(vType);
}
QualType Sema::CheckVectorLogicalOperands(ExprResult &LHS, ExprResult &RHS,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19123.53782.patch
Type: text/x-patch
Size: 3498 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160414/fe7fe0d1/attachment-0001.bin>
More information about the cfe-commits
mailing list