]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix folding of vector EQ/NE
authorRichard Sandiford <richard.sandiford@arm.com>
Sat, 20 Jul 2019 18:49:59 +0000 (18:49 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Sat, 20 Jul 2019 18:49:59 +0000 (18:49 +0000)
For vector1 != vector2, we returned false if any elements were equal,
rather than if all elements were equal.

2019-07-20  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
Backport from mainline
2019-07-10  Richard Sandiford  <richard.sandiford@arm.com>

* fold-const.c (fold_relational_const): Fix folding of
vector-to-scalar NE_EXPRs.
(test_vector_folding): Add more tests.

From-SVN: r273634

gcc/ChangeLog
gcc/fold-const.c

index af38e8be96a3aec261ec939d1ad99858034ed910..30b2ea0255ab5c3b056cfdfe60ac0b964c49aede 100644 (file)
@@ -1,3 +1,12 @@
+2019-07-20  Richard Sandiford  <richard.sandiford@arm.com>
+
+       Backport from mainline
+       2019-07-10  Richard Sandiford  <richard.sandiford@arm.com>
+
+       * fold-const.c (fold_relational_const): Fix folding of
+       vector-to-scalar NE_EXPRs.
+       (test_vector_folding): Add more tests.
+
 2019-07-19  Jason Merrill  <jason@redhat.com>
 
        PR c++/82081 - tail call optimization breaks noexcept
index a6b0b53be398f17657f6a082536abe77232d9b3a..f0e43b5fda239326630f17ef3ab33562c39461a3 100644 (file)
@@ -14050,13 +14050,13 @@ 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);
+             tree tmp = fold_relational_const (EQ_EXPR, type, elem0, elem1);
              if (tmp == NULL_TREE)
                return NULL_TREE;
              if (integer_zerop (tmp))
-               return constant_boolean_node (false, type);
+               return constant_boolean_node (code == NE_EXPR, type);
            }
-         return constant_boolean_node (true, type);
+         return constant_boolean_node (code == EQ_EXPR, type);
        }
       tree_vector_builder elts;
       if (!elts.new_binary_operation (type, op0, op1, false))
@@ -14827,6 +14827,7 @@ test_vector_folding ()
   tree type = build_vector_type (inner_type, 4);
   tree zero = build_zero_cst (type);
   tree one = build_one_cst (type);
+  tree index = build_index_vector (type, 0, 1);
 
   /* Verify equality tests that return a scalar boolean result.  */
   tree res_type = boolean_type_node;
@@ -14834,6 +14835,13 @@ test_vector_folding ()
   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)));
+  ASSERT_TRUE (integer_nonzerop (fold_build2 (NE_EXPR, res_type, index, one)));
+  ASSERT_FALSE (integer_nonzerop (fold_build2 (EQ_EXPR, res_type,
+                                              index, one)));
+  ASSERT_FALSE (integer_nonzerop (fold_build2 (NE_EXPR, res_type,
+                                             index, index)));
+  ASSERT_TRUE (integer_nonzerop (fold_build2 (EQ_EXPR, res_type,
+                                             index, index)));
 }
 
 /* Verify folding of VEC_DUPLICATE_EXPRs.  */