summaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorRichard Sandiford <richard.sandiford@arm.com>2019-12-05 14:20:38 +0000
committerRichard Sandiford <rsandifo@gcc.gnu.org>2019-12-05 14:20:38 +0000
commit56b4b16eb18e8af5615a9c7b56c6b5e7f9c3adf0 (patch)
tree5e41d9c2bd48e9c3b6f229b418d7f4fc32780b4d /gcc/fold-const.c
parent5a784d350c57d670775471bec847370ed7677666 (diff)
Check for bitwise identity when encoding VECTOR_CSTs (PR 92768)
This PR shows that we weren't checking for bitwise-identical values when trying to encode a VECTOR_CST, so -0.0 was treated the same as 0.0 for -fno-signed-zeros. The patch adds a new OEP flag to select that behaviour. 2019-12-05 Richard Sandiford <richard.sandiford@arm.com> gcc/ PR middle-end/92768 * tree-core.h (OEP_BITWISE): New flag. * fold-const.c (operand_compare::operand_equal_p): Handle it. * tree-vector-builder.h (tree_vector_builder::equal_p): Pass it. gcc/testsuite/ PR middle-end/92768 * gcc.dg/pr92768.c: New test. From-SVN: r279002
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 84b3bb06217..c5bd45a6e34 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -2938,6 +2938,11 @@ combine_comparisons (location_t loc,
If OEP_LEXICOGRAPHIC is set, then also handle expressions with side-effects
such as MODIFY_EXPR, RETURN_EXPR, as well as STATEMENT_LISTs.
+ If OEP_BITWISE is set, then require the values to be bitwise identical
+ rather than simply numerically equal. Do not take advantage of things
+ like math-related flags or undefined behavior; only return true for
+ values that are provably bitwise identical in all circumstances.
+
Unless OEP_MATCH_SIDE_EFFECTS is set, the function returns false on
any operand with side effect. This is unnecesarily conservative in the
case we know that arg0 and arg1 are in disjoint code paths (such as in
@@ -2967,6 +2972,11 @@ operand_compare::operand_equal_p (const_tree arg0, const_tree arg1,
if (!TREE_TYPE (arg0) || !TREE_TYPE (arg1))
return false;
+ /* Bitwise identity makes no sense if the values have different layouts. */
+ if ((flags & OEP_BITWISE)
+ && !tree_nop_conversion_p (TREE_TYPE (arg0), TREE_TYPE (arg1)))
+ return false;
+
/* We cannot consider pointers to different address space equal. */
if (POINTER_TYPE_P (TREE_TYPE (arg0))
&& POINTER_TYPE_P (TREE_TYPE (arg1))
@@ -3099,8 +3109,7 @@ operand_compare::operand_equal_p (const_tree arg0, const_tree arg1,
if (real_identical (&TREE_REAL_CST (arg0), &TREE_REAL_CST (arg1)))
return true;
-
- if (!HONOR_SIGNED_ZEROS (arg0))
+ if (!(flags & OEP_BITWISE) && !HONOR_SIGNED_ZEROS (arg0))
{
/* If we do not distinguish between signed and unsigned zero,
consider them equal. */
@@ -3152,7 +3161,9 @@ operand_compare::operand_equal_p (const_tree arg0, const_tree arg1,
break;
}
- if (flags & OEP_ONLY_CONST)
+ /* Don't handle more cases for OEP_BITWISE, since we can't guarantee that
+ two instances of undefined behavior will give identical results. */
+ if (flags & (OEP_ONLY_CONST | OEP_BITWISE))
return false;
/* Define macros to test an operand from arg0 and arg1 for equality and a