Skip to content

Commit c81e68a

Browse files
committed
value-relation: Fix up relation_union [PR108447]
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. The actual floating point relation problem isn't fixed by this patch though. 2023-01-19 Jakub Jelinek <[email protected]> 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.
1 parent 77a67e3 commit c81e68a

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

gcc/function-tests.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ test_ranges ()
583583
push_cfun (fun);
584584
range_tests ();
585585
range_op_tests ();
586+
relation_tests ();
586587

587588
build_cfg (fndecl);
588589
convert_to_ssa (fndecl);

gcc/selftest.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ extern void predict_cc_tests ();
244244
extern void pretty_print_cc_tests ();
245245
extern void range_tests ();
246246
extern void range_op_tests ();
247+
extern void relation_tests ();
247248
extern void gimple_range_tests ();
248249
extern void read_rtl_function_cc_tests ();
249250
extern void rtl_tests_cc_tests ();

gcc/value-relation.cc

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ relation_kind rr_union_table[VREL_LAST][VREL_LAST] = {
115115
{ VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING, VREL_VARYING,
116116
VREL_VARYING, VREL_VARYING, VREL_VARYING },
117117
// VREL_UNDEFINED
118-
{ VREL_VARYING, VREL_LT, VREL_LE, VREL_GT, VREL_GE, VREL_UNDEFINED,
118+
{ VREL_VARYING, VREL_UNDEFINED, VREL_LT, VREL_LE, VREL_GT, VREL_GE,
119119
VREL_EQ, VREL_NE },
120120
// VREL_LT
121121
{ VREL_VARYING, VREL_LT, VREL_LT, VREL_LE, VREL_NE, VREL_VARYING, VREL_LE,
@@ -1718,3 +1718,26 @@ equiv_relation_iterator::get_name (relation_kind *rel)
17181718
}
17191719
return NULL_TREE;
17201720
}
1721+
1722+
#if CHECKING_P
1723+
#include "selftest.h"
1724+
1725+
namespace selftest
1726+
{
1727+
void
1728+
relation_tests ()
1729+
{
1730+
// Verify commutativity of relation_intersect and relation_union.
1731+
for (relation_kind r1 = VREL_VARYING; r1 < VREL_PE8;
1732+
r1 = relation_kind (r1 + 1))
1733+
for (relation_kind r2 = VREL_VARYING; r2 < VREL_PE8;
1734+
r2 = relation_kind (r2 + 1))
1735+
{
1736+
ASSERT_EQ (relation_intersect (r1, r2), relation_intersect (r2, r1));
1737+
ASSERT_EQ (relation_union (r1, r2), relation_union (r2, r1));
1738+
}
1739+
}
1740+
1741+
} // namespace selftest
1742+
1743+
#endif // CHECKING_P

0 commit comments

Comments
 (0)