tree-ssa-sccvn.c (vn_reference_lookup_3): Handle arbitrary memset constants via nativ...
authorRichard Biener <rguenther@suse.de>
Wed, 23 May 2018 07:08:43 +0000 (07:08 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 23 May 2018 07:08:43 +0000 (07:08 +0000)
2018-05-23  Richard Biener  <rguenther@suse.de>

* tree-ssa-sccvn.c (vn_reference_lookup_3): Handle arbitrary
memset constants via native_interpret_expr.

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

From-SVN: r260565

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

index 79a5e374d5a88acc846b07587e16a3521549da7b..fbb0120c497ff94748f41e825214d10b167a7cc4 100644 (file)
@@ -1,3 +1,8 @@
+2018-05-23  Richard Biener  <rguenther@suse.de>
+
+       * tree-ssa-sccvn.c (vn_reference_lookup_3): Handle arbitrary
+       memset constants via native_interpret_expr.
+
 2018-05-22  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR target/85345
index 21e58d3e3a7d3bee8479f2ef71ce33bb6cd72c36..6bd7a1546cd4188a914ae2277fb73699dd9b5ef8 100644 (file)
@@ -1,3 +1,7 @@
+2018-05-23  Richard Biener  <rguenther@suse.de>
+
+       * gcc.dg/tree-ssa/ssa-fre-65.c: New testcase.
+
 2018-05-22  Janus Weil  <janus@gcc.gnu.org>
 
        PR fortran/85841
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-65.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-65.c
new file mode 100644 (file)
index 0000000..87ba666
--- /dev/null
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-fre1-details -fdump-tree-dse1-details" } */
+
+typedef unsigned char v16qi __attribute__((vector_size(16)));
+typedef unsigned short v8hi __attribute__((vector_size(16)));
+typedef unsigned int v4si __attribute__((vector_size(16)));
+void foo(char *dest)
+{
+  unsigned char x[256] __attribute__((aligned(16)));
+  __builtin_memset (x, 23, 256);
+  v16qi resqi = *(v16qi *)&x[16];
+  v8hi reshi = *(v8hi *)&x[16];
+  v4si ressi = *(v4si *)&x[16];
+  *(v16qi *)dest = resqi;
+  *(v8hi *)(dest + 16) = reshi;
+  *(v4si *)(dest + 32) = ressi;
+}
+
+/* { dg-final { scan-tree-dump-times "Replaced MEM" 3 "fre1" } } */
+/* { dg-final { scan-tree-dump-times "Deleted dead call" 1 "dse1" } } */
index 884cce12bb36e95e66163ccb86f3b1efe6a1cba9..96e80c7b5a3058553a8f69921976b9326a001017 100644 (file)
@@ -1959,9 +1959,9 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *vr_,
   if (is_gimple_reg_type (vr->type)
       && gimple_call_builtin_p (def_stmt, BUILT_IN_MEMSET)
       && (integer_zerop (gimple_call_arg (def_stmt, 1))
-         || (INTEGRAL_TYPE_P (vr->type)
+         || ((TREE_CODE (gimple_call_arg (def_stmt, 1)) == INTEGER_CST
+              || (INTEGRAL_TYPE_P (vr->type) && known_eq (ref->size, 8)))
              && CHAR_BIT == 8 && BITS_PER_UNIT == 8
-             && known_eq (ref->size, 8)
              && known_eq (ref->size, maxsize)
              && offset.is_constant (&offseti)
              && offseti % BITS_PER_UNIT == 0))
@@ -2030,7 +2030,8 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *vr_,
          tree val;
          if (integer_zerop (gimple_call_arg (def_stmt, 1)))
            val = build_zero_cst (vr->type);
-         else
+         else if (INTEGRAL_TYPE_P (vr->type)
+                  && known_eq (ref->size, 8))
            {
              code_helper rcode = NOP_EXPR;
              tree ops[3] = {};
@@ -2041,6 +2042,16 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *vr_,
                      && SSA_NAME_OCCURS_IN_ABNORMAL_PHI (val)))
                return (void *)-1;
            }
+         else
+           {
+             unsigned len = TREE_INT_CST_LOW (TYPE_SIZE_UNIT (vr->type));
+             unsigned char *buf = XALLOCAVEC (unsigned char, len);
+             memset (buf, TREE_INT_CST_LOW (gimple_call_arg (def_stmt, 1)),
+                     len);
+             val = native_interpret_expr (vr->type, buf, len);
+             if (!val)
+               return (void *)-1;
+           }
          return vn_reference_lookup_or_insert_for_pieces
                   (vuse, vr->set, vr->type, vr->operands, val);
        }