value-relation: Fix up relation_union [PR108447]

Message ID Y8mlNDm8kwAfjB5F@tucnak
State New
Headers
Series value-relation: Fix up relation_union [PR108447] |

Commit Message

Jakub Jelinek Jan. 19, 2023, 8:16 p.m. UTC
  Hi!

While looking at the PR, I've noticed one row in rr_union_table
is wrong.  relation_union should be commutative, but due to that
bug is not.  The following patch adds a self-test for that
property (fails without the first hunk) and fixes that line.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

The actual floating point relation problem isn't fixed by this patch
though.

2023-01-19  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/108447
	* value-relation.cc (rr_union_table): Fix VREL_UNDEFINED row order.
	(relation_tests): Add self-tests for relation_{intersect,union}
	commutativity.
	* selftest.h (relation_tests): Declare.
	* function-tests.cc (test_ranges): Call it.


	Jakub
  

Comments

Andrew MacLeod Jan. 19, 2023, 9:38 p.m. UTC | #1
On 1/19/23 15:16, Jakub Jelinek wrote:
> Hi!
>
> While looking at the PR, I've noticed one row in rr_union_table
> is wrong.  relation_union should be commutative, but due to that
> bug is not.  The following patch adds a self-test for that
> property (fails without the first hunk) and fixes that line.
>
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> The actual floating point relation problem isn't fixed by this patch
> though.
>
> 2023-01-19  Jakub Jelinek  <jakub@redhat.com>
>
> 	PR tree-optimization/108447
> 	* value-relation.cc (rr_union_table): Fix VREL_UNDEFINED row order.
> 	(relation_tests): Add self-tests for relation_{intersect,union}
> 	commutativity.
> 	* selftest.h (relation_tests): Declare.
> 	* function-tests.cc (test_ranges): Call it.
> <...>

> +relation_tests ()
> +{
> +  // Verify commutativity of relation_intersect and relation_union.
> +  for (relation_kind r1 = VREL_VARYING; r1 < VREL_PE8;
> +       r1 = relation_kind (r1 + 1))
> +    for (relation_kind r2 = VREL_VARYING; r2 < VREL_PE8;
> +	 r2 = relation_kind (r2 + 1))
> +      {
> +	ASSERT_EQ (relation_intersect (r1, r2), relation_intersect (r2, r1));
> +	ASSERT_EQ (relation_union (r1, r2), relation_union (r2, r1));
> +      }
> +}

Easy test, I like it.
  

Patch

--- gcc/value-relation.cc.jj	2023-01-19 18:33:47.296304283 +0100
+++ gcc/value-relation.cc	2023-01-19 18:41:24.280658434 +0100
@@ -115,7 +115,7 @@  relation_kind rr_union_table[VREL_LAST][
   { VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING,
     VREL_VARYING, VREL_VARYING, VREL_VARYING },
 // VREL_UNDEFINED
-  { VREL_VARYING, VREL_LT, VREL_LE, VREL_GT, VREL_GE, VREL_UNDEFINED,
+  { VREL_VARYING, VREL_UNDEFINED, VREL_LT, VREL_LE, VREL_GT, VREL_GE,
     VREL_EQ, VREL_NE },
 // VREL_LT
   { VREL_VARYING, VREL_LT, VREL_LT, VREL_LE, VREL_NE, VREL_VARYING, VREL_LE,
@@ -1718,3 +1718,26 @@  equiv_relation_iterator::get_name (relat
     }
   return NULL_TREE;
 }
+
+#if CHECKING_P
+#include "selftest.h"
+
+namespace selftest
+{
+void
+relation_tests ()
+{
+  // Verify commutativity of relation_intersect and relation_union.
+  for (relation_kind r1 = VREL_VARYING; r1 < VREL_PE8;
+       r1 = relation_kind (r1 + 1))
+    for (relation_kind r2 = VREL_VARYING; r2 < VREL_PE8;
+	 r2 = relation_kind (r2 + 1))
+      {
+	ASSERT_EQ (relation_intersect (r1, r2), relation_intersect (r2, r1));
+	ASSERT_EQ (relation_union (r1, r2), relation_union (r2, r1));
+      }
+}
+
+} // namespace selftest
+
+#endif // CHECKING_P
--- gcc/selftest.h.jj	2023-01-02 09:32:34.083116265 +0100
+++ gcc/selftest.h	2023-01-19 18:38:58.267781163 +0100
@@ -244,6 +244,7 @@  extern void predict_cc_tests ();
 extern void pretty_print_cc_tests ();
 extern void range_tests ();
 extern void range_op_tests ();
+extern void relation_tests ();
 extern void gimple_range_tests ();
 extern void read_rtl_function_cc_tests ();
 extern void rtl_tests_cc_tests ();
--- gcc/function-tests.cc.jj	2023-01-02 09:32:51.941858230 +0100
+++ gcc/function-tests.cc	2023-01-19 18:39:13.942553180 +0100
@@ -583,6 +583,7 @@  test_ranges ()
   push_cfun (fun);
   range_tests ();
   range_op_tests ();
+  relation_tests ();
 
   build_cfg (fndecl);
   convert_to_ssa (fndecl);