]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Check for bitwise identity when encoding VECTOR_CSTs [PR92768]
authorRichard Sandiford <richard.sandiford@arm.com>
Thu, 5 Dec 2019 14:20:38 +0000 (14:20 +0000)
committerRichard Sandiford <richard.sandiford@arm.com>
Tue, 18 Feb 2020 12:26:03 +0000 (12:26 +0000)
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.

2020-02-18  Richard Sandiford  <richard.sandiford@arm.com>

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

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.

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr92768.c [new file with mode: 0644]
gcc/tree-core.h
gcc/tree-vector-builder.h

index 874de008609f63477afc668e70f4bab96c395b05..5cad2832d938d20034334dea6273ba1001ecd682 100644 (file)
@@ -1,3 +1,13 @@
+2020-02-18  Richard Sandiford  <richard.sandiford@arm.com>
+
+       Backport from mainline
+       2019-12-05  Richard Sandiford  <richard.sandiford@arm.com>
+
+       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.
+
 2020-02-18  Richard Sandiford  <richard.sandiford@arm.com>
 
        Backport from mainline
index 9feaea9fde57222e06c155b4a5284511ffa12a45..c717f24501e376ba7afd94946158287f02fd5117 100644 (file)
@@ -2932,6 +2932,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
@@ -2978,6 +2983,11 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
   if (!TREE_TYPE (arg0) || !TREE_TYPE (arg1))
     return 0;
 
+  /* 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 0;
+
   /* We cannot consider pointers to different address space equal.  */
   if (POINTER_TYPE_P (TREE_TYPE (arg0))
       && POINTER_TYPE_P (TREE_TYPE (arg1))
@@ -3110,8 +3120,7 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
        if (real_identical (&TREE_REAL_CST (arg0), &TREE_REAL_CST (arg1)))
          return 1;
 
-
-       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.  */
@@ -3163,7 +3172,9 @@ operand_equal_p (const_tree arg0, const_tree arg1, unsigned int flags)
        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 0;
 
 /* Define macros to test an operand from arg0 and arg1 for equality and a
index d02ad44ceff2be252dba5fff6a444bec20da93bb..4a17cbdf03d8bec35103efa77c2074887f372dc6 100644 (file)
@@ -1,3 +1,8 @@
+2020-02-18  Richard Sandiford  <richard.sandiford@arm.com>
+
+       PR middle-end/92768
+       * gcc.dg/pr92768.c: New test.
+
 2020-02-18  Richard Sandiford  <richard.sandiford@arm.com>
 
        PR middle-end/90313
diff --git a/gcc/testsuite/gcc.dg/pr92768.c b/gcc/testsuite/gcc.dg/pr92768.c
new file mode 100644 (file)
index 0000000..e2a3f9c
--- /dev/null
@@ -0,0 +1,7 @@
+/* PR tree-optimization/92768 */
+/* { dg-options "-O2 -fno-signed-zeros -fdump-tree-optimized -w -Wno-psabi" } */
+
+typedef float v4sf __attribute__((vector_size(16)));
+v4sf f () { return (v4sf) { 0.0, -0.0, 0.0, -0.0 }; }
+
+/* { dg-final { scan-tree-dump {{ 0\.0, -0\.0, 0\.0, -0\.0 }} "optimized" } } */
index fbed0c379b250eef3ad02cc44f60e43ad9728148..41d052949365a629e74e63c1f92dfcb3e724c2e0 100644 (file)
@@ -851,7 +851,8 @@ enum operand_equal_flag {
   /* Internal within inchash::add_expr:  */
   OEP_HASH_CHECK = 32,
   /* Makes operand_equal_p handle more expressions:  */
-  OEP_LEXICOGRAPHIC = 64
+  OEP_LEXICOGRAPHIC = 64,
+  OEP_BITWISE = 128
 };
 
 /* Enum and arrays used for tree allocation stats.
index 0e36cd171395ecdb73e4528bcd9fb30ad4e94d71..13af74ad834090f07cd6b4cc82b7657f85f2673f 100644 (file)
@@ -82,7 +82,7 @@ tree_vector_builder::new_vector (tree type, unsigned int npatterns,
 inline bool
 tree_vector_builder::equal_p (const_tree elt1, const_tree elt2) const
 {
-  return operand_equal_p (elt1, elt2, 0);
+  return operand_equal_p (elt1, elt2, OEP_BITWISE);
 }
 
 /* Return true if a stepped representation is OK.  We don't allow