Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 648689c

Browse files
committed
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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@266366 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent f054cc1 commit 648689c

File tree

3 files changed

+38
-11
lines changed

3 files changed

+38
-11
lines changed

lib/Sema/SemaExpr.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7929,14 +7929,16 @@ QualType Sema::CheckVectorOperands(ExprResult &LHS, ExprResult &RHS,
79297929
return RHSType;
79307930
}
79317931

7932-
// If we're allowing lax vector conversions, only the total (data) size
7933-
// needs to be the same.
7934-
// FIXME: Should we really be allowing this?
7935-
// FIXME: We really just pick the LHS type arbitrarily?
7936-
if (isLaxVectorConversion(RHSType, LHSType)) {
7937-
QualType resultType = LHSType;
7938-
RHS = ImpCastExprToType(RHS.get(), resultType, CK_BitCast);
7939-
return resultType;
7932+
// If we're allowing lax vector conversions, only the total (data) size needs
7933+
// to be the same. If one of the types is scalar, the result is always the
7934+
// vector type. Don't allow this if the scalar operand is an lvalue.
7935+
QualType VecType = LHSVecType ? LHSType : RHSType;
7936+
QualType ScalarType = LHSVecType ? RHSType : LHSType;
7937+
ExprResult *ScalarExpr = LHSVecType ? &RHS : &LHS;
7938+
if (isLaxVectorConversion(ScalarType, VecType) &&
7939+
!ScalarExpr->get()->isLValue()) {
7940+
*ScalarExpr = ImpCastExprToType(ScalarExpr->get(), VecType, CK_BitCast);
7941+
return VecType;
79407942
}
79417943

79427944
// Okay, the expression is invalid.
@@ -9480,7 +9482,7 @@ QualType Sema::CheckVectorCompareOperands(ExprResult &LHS, ExprResult &RHS,
94809482
}
94819483

94829484
// Return a signed type for the vector.
9483-
return GetSignedVectorType(LHSType);
9485+
return GetSignedVectorType(vType);
94849486
}
94859487

94869488
QualType Sema::CheckVectorLogicalOperands(ExprResult &LHS, ExprResult &RHS,

test/CodeGen/vector.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// 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
1+
// RUN: %clang_cc1 -triple i386-apple-darwin9 -O1 -target-cpu core2 -debug-info-kind=limited -emit-llvm %s -o - | FileCheck %s
22
typedef short __v4hi __attribute__ ((__vector_size__ (8)));
33

44
void test1() {
@@ -62,3 +62,23 @@ void extractinttypes() {
6262
extern __typeof(_mm_extract_epi16(_mm_setzero_si128(), 3)) check_result_int;
6363
extern __typeof(_mm_extract_epi32(_mm_setzero_si128(), 3)) check_result_int;
6464
}
65+
66+
// Test some logic around our lax vector comparison rules with integers.
67+
68+
typedef int vec_int1 __attribute__((vector_size(4)));
69+
vec_int1 lax_vector_compare1(int x, vec_int1 y) {
70+
y = x == y;
71+
return y;
72+
}
73+
74+
// CHECK: define i32 @lax_vector_compare1(i32 {{.*}}, i32 {{.*}})
75+
// CHECK: icmp eq <1 x i32>
76+
77+
typedef int vec_int2 __attribute__((vector_size(8)));
78+
vec_int2 lax_vector_compare2(long long x, vec_int2 y) {
79+
y = x == y;
80+
return y;
81+
}
82+
83+
// CHECK: define void @lax_vector_compare2(<2 x i32>* {{.*sret.*}}, i64 {{.*}}, i64 {{.*}})
84+
// CHECK: icmp eq <2 x i32>

test/Sema/vector-cast.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,12 @@ void f4() {
5050
float2 f2;
5151
double d;
5252
f2 += d;
53-
d += f2;
53+
// We used to allow the next statement, but we've always rejected the next two
54+
// statements
55+
// FIXME: This diagnostic is inaccurate.
56+
d += f2; // expected-error {{cannot convert between vector values of different size}}
57+
d = f2; // expected-error {{assigning to 'double' from incompatible type 'float2'}}
58+
d = d + f2; // expected-error {{assigning to 'double' from incompatible type 'float2'}}
5459
}
5560

5661
// rdar://15931426

0 commit comments

Comments
 (0)