diff mbox series

Fix folding of vector EQ/NE

Message ID mptimsanov6.fsf@arm.com
State New
Headers show
Series Fix folding of vector EQ/NE | expand

Commit Message

Richard Sandiford July 10, 2019, 10:52 a.m. UTC
For vector1 != vector2, we returned false if any elements were equal,
rather than if all elements were equal.

Tested on aarch64-linux-gnu, armeb-eabi and x86_64-linux-gnu.
OK for trunk, gcc 9 and gcc 8?

Richard


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

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

Comments

Richard Biener July 10, 2019, 4:16 p.m. UTC | #1
On July 10, 2019 12:52:13 PM GMT+02:00, Richard Sandiford <richard.sandiford@arm.com> wrote:
>For vector1 != vector2, we returned false if any elements were equal,
>rather than if all elements were equal.
>
>Tested on aarch64-linux-gnu, armeb-eabi and x86_64-linux-gnu.
>OK for trunk, gcc 9 and gcc 8?

Ok. 

Richard. 

>Richard
>
>
>2019-07-10  Richard Sandiford  <richard.sandiford@arm.com>
>
>gcc/
>	* fold-const.c (fold_relational_const): Fix folding of
>	vector-to-scalar NE_EXPRs.
>	(test_vector_folding): Add more tests.
>
>Index: gcc/fold-const.c
>===================================================================
>--- gcc/fold-const.c	2019-06-18 09:35:52.785887115 +0100
>+++ gcc/fold-const.c	2019-07-10 11:49:25.907674865 +0100
>@@ -14026,13 +14026,13 @@ fold_relational_const (enum tree_code co
> 	    {
> 	      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))
>@@ -14803,6 +14803,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;
>@@ -14810,6 +14811,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.  */
diff mbox series

Patch

Index: gcc/fold-const.c
===================================================================
--- gcc/fold-const.c	2019-06-18 09:35:52.785887115 +0100
+++ gcc/fold-const.c	2019-07-10 11:49:25.907674865 +0100
@@ -14026,13 +14026,13 @@  fold_relational_const (enum tree_code co
 	    {
 	      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))
@@ -14803,6 +14803,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;
@@ -14810,6 +14811,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.  */