[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 09:34:26 PDT 2016


rnk created this revision.
rnk added a reviewer: rsmith.
rnk added a subscriber: cfe-commits.

Fixes PR27258

http://reviews.llvm.org/D19123

Files:
  lib/Sema/SemaExpr.cpp
  test/CodeGen/vector.c

Index: test/CodeGen/vector.c
===================================================================
--- test/CodeGen/vector.c
+++ 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: lib/Sema/SemaExpr.cpp
===================================================================
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -7932,11 +7932,12 @@
   // 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;
+  QualType VecType = LHSVecType ? LHSType : RHSType;
+  QualType ScalarType = LHSVecType ? RHSType : LHSType;
+  ExprResult *ScalarExpr = LHSVecType ? &RHS : &LHS;
+  if (isLaxVectorConversion(ScalarType, VecType)) {
+    *ScalarExpr = ImpCastExprToType(ScalarExpr->get(), VecType, CK_BitCast);
+    return VecType;
   }
 
   // Okay, the expression is invalid.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19123.53745.patch
Type: text/x-patch
Size: 2212 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160414/b9eacd20/attachment-0001.bin>


More information about the cfe-commits mailing list