Author: rnk Date: Thu Apr 14 16:03:38 2016 New Revision: 266366 URL: http://llvm.org/viewvc/llvm-project?rev=266366&view=rev Log: In vector comparisons, handle scalar LHS just as we handle scalar RHS
Summary: Fixes PR27258 Reviewers: rsmith Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D19123 Modified: cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/test/CodeGen/vector.c cfe/trunk/test/Sema/vector-cast.c Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=266366&r1=266365&r2=266366&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Apr 14 16:03:38 2016 @@ -7929,14 +7929,16 @@ QualType Sema::CheckVectorOperands(ExprR 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 @@ QualType Sema::CheckVectorCompareOperand } // Return a signed type for the vector. - return GetSignedVectorType(LHSType); + return GetSignedVectorType(vType); } QualType Sema::CheckVectorLogicalOperands(ExprResult &LHS, ExprResult &RHS, Modified: cfe/trunk/test/CodeGen/vector.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/vector.c?rev=266366&r1=266365&r2=266366&view=diff ============================================================================== --- cfe/trunk/test/CodeGen/vector.c (original) +++ cfe/trunk/test/CodeGen/vector.c Thu Apr 14 16:03:38 2016 @@ -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 @@ void extractinttypes() { 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> Modified: cfe/trunk/test/Sema/vector-cast.c URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/vector-cast.c?rev=266366&r1=266365&r2=266366&view=diff ============================================================================== --- cfe/trunk/test/Sema/vector-cast.c (original) +++ cfe/trunk/test/Sema/vector-cast.c Thu Apr 14 16:03:38 2016 @@ -50,7 +50,12 @@ void f4() { 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 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits