tree-optimization/93508 - make VN translate through _chk and valueize length
authorRichard Biener <rguenther@suse.de>
Thu, 27 Feb 2020 12:46:34 +0000 (13:46 +0100)
committerRichard Biener <rguenther@suse.de>
Thu, 27 Feb 2020 12:47:50 +0000 (13:47 +0100)
Value-numbering failed to handle __builtin_{memcpy,memset,...}_chk
variants when removing abstraction and also failed to use the
value-numbering lattice when requiring the length argument of the
call to be constant.

2020-02-27  Richard Biener  <rguenther@suse.de>

PR tree-optimization/93508
* tree-ssa-sccvn.c (vn_reference_lookup_3): Handle _CHK like
non-_CHK variants.  Valueize their length arguments.

* gcc.dg/tree-ssa/ssa-fre-85.c: New testcase.

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-87.c [new file with mode: 0644]
gcc/tree-ssa-sccvn.c

index 97419847b6250d955b45f8496780838a543e6b16..8c9b7906772c311210d88045299e68affbe3f057 100644 (file)
@@ -1,3 +1,9 @@
+2020-02-27  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/93508
+       * tree-ssa-sccvn.c (vn_reference_lookup_3): Handle _CHK like
+       non-_CHK variants.  Valueize their length arguments.
+
 2020-02-27  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/93953
index fa18a159687874a977bdd4c1510bdd7be4f9da1c..6b7b0a2f3d46320dcdde1fb7124e8bf00277fadc 100644 (file)
@@ -1,3 +1,8 @@
+2020-02-27  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/93508
+       * gcc.dg/tree-ssa/ssa-fre-85.c: New testcase.
+
 2020-02-27  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/93953
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-87.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-87.c
new file mode 100644 (file)
index 0000000..6dace16
--- /dev/null
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-fre1" } */
+
+unsigned int foo(unsigned int x, int *p)
+{
+  unsigned int src = x;
+  unsigned int dst;
+  *p = sizeof (unsigned int);
+  __builtin___memcpy_chk (&dst, &src, *p, 16);
+  return dst;
+}
+
+/* { dg-final { scan-tree-dump "return x" "fre1" } } */
index 0487f59f13f7768414e82274f0af3bbae4c76535..e260ca4eed179898175f93433d99ca214af099e4 100644 (file)
@@ -2537,7 +2537,8 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_,
      from that definition.
      1) Memset.  */
   if (is_gimple_reg_type (vr->type)
-      && gimple_call_builtin_p (def_stmt, BUILT_IN_MEMSET)
+      && (gimple_call_builtin_p (def_stmt, BUILT_IN_MEMSET)
+         || gimple_call_builtin_p (def_stmt, BUILT_IN_MEMSET_CHK))
       && (integer_zerop (gimple_call_arg (def_stmt, 1))
          || ((TREE_CODE (gimple_call_arg (def_stmt, 1)) == INTEGER_CST
               || (INTEGRAL_TYPE_P (vr->type) && known_eq (ref->size, 8)))
@@ -2548,7 +2549,9 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_,
              && ref->size.is_constant (&sizei)
              && (offseti % BITS_PER_UNIT == 0
                  || TREE_CODE (gimple_call_arg (def_stmt, 1)) == INTEGER_CST)))
-      && poly_int_tree_p (gimple_call_arg (def_stmt, 2))
+      && (poly_int_tree_p (gimple_call_arg (def_stmt, 2))
+         || (TREE_CODE (gimple_call_arg (def_stmt, 2)) == SSA_NAME
+             && poly_int_tree_p (SSA_VAL (gimple_call_arg (def_stmt, 2)))))
       && (TREE_CODE (gimple_call_arg (def_stmt, 0)) == ADDR_EXPR
          || TREE_CODE (gimple_call_arg (def_stmt, 0)) == SSA_NAME))
     {
@@ -2609,6 +2612,8 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_,
        return (void *)-1;
       tree len = gimple_call_arg (def_stmt, 2);
       HOST_WIDE_INT leni, offset2i;
+      if (TREE_CODE (len) == SSA_NAME)
+       len = SSA_VAL (len);
       /* Sometimes the above trickery is smarter than alias analysis.  Take
          advantage of that.  */
       if (!ranges_maybe_overlap_p (offset, maxsize, offset2,
@@ -3149,13 +3154,19 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *data_,
           && is_gimple_reg_type (vr->type)
           /* ???  Handle BCOPY as well.  */
           && (gimple_call_builtin_p (def_stmt, BUILT_IN_MEMCPY)
+              || gimple_call_builtin_p (def_stmt, BUILT_IN_MEMCPY_CHK)
               || gimple_call_builtin_p (def_stmt, BUILT_IN_MEMPCPY)
-              || gimple_call_builtin_p (def_stmt, BUILT_IN_MEMMOVE))
+              || gimple_call_builtin_p (def_stmt, BUILT_IN_MEMPCPY_CHK)
+              || gimple_call_builtin_p (def_stmt, BUILT_IN_MEMMOVE)
+              || gimple_call_builtin_p (def_stmt, BUILT_IN_MEMMOVE_CHK))
           && (TREE_CODE (gimple_call_arg (def_stmt, 0)) == ADDR_EXPR
               || TREE_CODE (gimple_call_arg (def_stmt, 0)) == SSA_NAME)
           && (TREE_CODE (gimple_call_arg (def_stmt, 1)) == ADDR_EXPR
               || TREE_CODE (gimple_call_arg (def_stmt, 1)) == SSA_NAME)
-          && poly_int_tree_p (gimple_call_arg (def_stmt, 2), &copy_size)
+          && (poly_int_tree_p (gimple_call_arg (def_stmt, 2), &copy_size)
+              || (TREE_CODE (gimple_call_arg (def_stmt, 2)) == SSA_NAME
+                  && poly_int_tree_p (SSA_VAL (gimple_call_arg (def_stmt, 2)),
+                                      &copy_size)))
           /* Handling this is more complicated, give up for now.  */
           && data->partial_defs.is_empty ())
     {