On 10/02/2015 08:04 AM, Ilya Enkovich wrote:
Hi,
This patch makes C/C++ FE to use boolean vector as a resulting type for vector
comparison. As a result vector comparison in source code now parsed into
VEC_COND_EXPR, it required a testcase fix-up.
Thanks,
Ilya
--
gcc/c
2015-10-02 Ilya Enkovich <enkovich....@gmail.com>
* c-typeck.c (build_conditional_expr): Use boolean vector
type for vector comparison.
(build_vec_cmp): New.
(build_binary_op): Use build_vec_cmp for comparison.
gcc/cp
2015-10-02 Ilya Enkovich <enkovich....@gmail.com>
* call.c (build_conditional_expr_1): Use boolean vector
type for vector comparison.
* typeck.c (build_vec_cmp): New.
(cp_build_binary_op): Use build_vec_cmp for comparison.
gcc/testsuite/
2015-10-02 Ilya Enkovich <enkovich....@gmail.com>
* g++.dg/ext/vector22.C: Allow VEC_COND_EXPR.
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 3b26231..3f64d76 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -10220,6 +10232,19 @@ push_cleanup (tree decl, tree cleanup, bool eh_only)
STATEMENT_LIST_STMT_EXPR (list) = stmt_expr;
}
+/* Build a vector comparison using VEC_COND_EXPR. */
Please make sure your function comments include descriptions of all the
arguments and return values.
+
+static tree
+build_vec_cmp (tree_code code, tree type,
+ tree arg0, tree arg1)
+{
+ tree zero_vec = build_zero_cst (type);
+ tree minus_one_vec = build_minus_one_cst (type);
+ tree cmp_type = build_same_sized_truth_vector_type (type);
+ tree cmp = build2 (code, cmp_type, arg0, arg1);
+ return build3 (VEC_COND_EXPR, type, cmp, minus_one_vec, zero_vec);
+}
Isn't this implementation the same for C & C++? Does it make sense to
put it in c-family/c-common.c?
+
/* Build a binary-operation expression without default conversions.
CODE is the kind of expression to build.
LOCATION is the operator's location.
@@ -10786,7 +10811,8 @@ build_binary_op (location_t location, enum tree_code
code,
result_type = build_opaque_vector_type (intt,
TYPE_VECTOR_SUBPARTS (type0));
converted = 1;
- break;
+ ret = build_vec_cmp (resultcode, result_type, op0, op1);
+ goto return_build_binary_op;
I suspect there's some kind of whitespace/tab problem. Those two lines
should be indented the same, right?
}
if (FLOAT_TYPE_P (type0) || FLOAT_TYPE_P (type1))
warning_at (location,
@@ -10938,7 +10964,8 @@ build_binary_op (location_t location, enum tree_code
code,
result_type = build_opaque_vector_type (intt,
TYPE_VECTOR_SUBPARTS (type0));
converted = 1;
- break;
+ ret = build_vec_cmp (resultcode, result_type, op0, op1);
+ goto return_build_binary_op;
Similarly here.
With the items above fixed, this is OK.
However, more generally, do we need to do anything for the other languages?
Jeff