aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 103ed2d..bf177b6 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -13898,7 +13898,6 @@ fold_relational_const (enum tree_code code, tree type, tree op0, tree op1)
if (!VECTOR_TYPE_P (type))
{
/* Have vector comparison with scalar boolean result. */
- bool result = true;
gcc_assert ((code == EQ_EXPR || code == NE_EXPR)
&& VECTOR_CST_NELTS (op0) == VECTOR_CST_NELTS (op1));
for (unsigned i = 0; i < VECTOR_CST_NELTS (op0); i++)
@@ -13906,11 +13905,12 @@ fold_relational_const (enum tree_code code, tree type, tree op0, tree op1)
tree elem0 = VECTOR_CST_ELT (op0, i);
tree elem1 = VECTOR_CST_ELT (op1, i);
tree tmp = fold_relational_const (code, type, elem0, elem1);
- result &= integer_onep (tmp);
+ if (tmp == NULL_TREE)
+ return NULL_TREE;
+ if (integer_zerop (tmp))
+ return constant_boolean_node (false, type);
}
- if (code == NE_EXPR)
- result = !result;
- return constant_boolean_node (result, type);
+ return constant_boolean_node (true, type);
}
unsigned count = VECTOR_CST_NELTS (op0);
tree *elts = XALLOCAVEC (tree, count);
@@ -14518,12 +14518,32 @@ test_arithmetic_folding ()
x);
}
+/* Verify that various binary operations on vectors are folded
+ correctly. */
+
+static void
+test_vector_folding ()
+{
+ tree inner_type = integer_type_node;
+ tree type = build_vector_type (inner_type, 4);
+ tree zero = build_zero_cst (type);
+ tree one = build_one_cst (type);
+
+ /* Verify equality tests that return a scalar boolean result. */
+ tree res_type = boolean_type_node;
+ ASSERT_FALSE (integer_nonzerop (fold_build2 (EQ_EXPR, res_type, zero, one)));
+ ASSERT_TRUE (integer_nonzerop (fold_build2 (EQ_EXPR, res_type, zero, zero)));
+ ASSERT_TRUE (integer_nonzerop (fold_build2 (NE_EXPR, res_type, zero, one)));
+ ASSERT_FALSE (integer_nonzerop (fold_build2 (NE_EXPR, res_type, one, one)));
+}
+
/* Run all of the selftests within this file. */
void
fold_const_c_tests ()
{
test_arithmetic_folding ();
+ test_vector_folding ();
}
} // namespace selftest