re PR tree-optimization/83128 (Unable to optimize {m,c}alloc when strings builtin...
authorRichard Biener <rguenther@suse.de>
Fri, 24 Nov 2017 09:40:40 +0000 (09:40 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Fri, 24 Nov 2017 09:40:40 +0000 (09:40 +0000)
2017-11-24  Richard Biener  <rguenther@suse.de>

PR tree-optimization/83128
* tree-ssa-sccvn.c (fully_constant_vn_reference_p): Handle STRING_CSTs.
(vn_reference_lookup_3): Likewise.

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

From-SVN: r255136

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

index 8f34f37b3652206666288f121eb91c644ca770ee..cb6c0510535f2a9603b421af7af2ba3724e623a7 100644 (file)
@@ -1,3 +1,9 @@
+2017-11-24  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/83128
+       * tree-ssa-sccvn.c (fully_constant_vn_reference_p): Handle STRING_CSTs.
+       (vn_reference_lookup_3): Likewise.
+
 2017-11-24  Jakub Jelinek  <jakub@redhat.com>
 
        PR sanitizer/83014
index eef79af85a494d397eea242b70981aa65b8b34c3..019ff2afc2bca36c6c4bbe7233653112dadfa089 100644 (file)
@@ -1,3 +1,8 @@
+2017-11-24  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/83128
+       * gcc.dg/tree-ssa/ssa-fre-62.c: New testcase.
+
 2017-11-24  Jakub Jelinek  <jakub@redhat.com>
 
        PR sanitizer/83014
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-62.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-62.c
new file mode 100644 (file)
index 0000000..f02dfe2
--- /dev/null
@@ -0,0 +1,11 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fdump-tree-fre1" } */
+
+char f()
+{
+  char *i = (char*)__builtin_malloc(100);
+  __builtin_memcpy(i, "a", 1);
+  return i[0];
+}
+
+/* { dg-final { scan-tree-dump "return 97;" "fre1" } } */
index d0ff30199e617b6967776dd4780b2a9851531001..63a3db99d03fd9c332a3a875048cb4da7c76816e 100644 (file)
@@ -1388,10 +1388,14 @@ fully_constant_vn_reference_p (vn_reference_t ref)
       else if (base->opcode == MEM_REF
               && base[1].opcode == ADDR_EXPR
               && (TREE_CODE (TREE_OPERAND (base[1].op0, 0)) == VAR_DECL
-                  || TREE_CODE (TREE_OPERAND (base[1].op0, 0)) == CONST_DECL))
+                  || TREE_CODE (TREE_OPERAND (base[1].op0, 0)) == CONST_DECL
+                  || TREE_CODE (TREE_OPERAND (base[1].op0, 0)) == STRING_CST))
        {
          decl = TREE_OPERAND (base[1].op0, 0);
-         ctor = ctor_for_folding (decl);
+         if (TREE_CODE (decl) == STRING_CST)
+           ctor = decl;
+         else
+           ctor = ctor_for_folding (decl);
        }
       if (ctor == NULL_TREE)
        return build_zero_cst (ref->type);
@@ -2331,7 +2335,8 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *vr_,
              rhs = TREE_OPERAND (tem, 0);
              rhs_offset += tree_to_uhwi (TREE_OPERAND (tem, 1));
            }
-         else if (DECL_P (tem))
+         else if (DECL_P (tem)
+                  || TREE_CODE (tem) == STRING_CST)
            rhs = build_fold_addr_expr (tem);
          else
            return (void *)-1;