From 6a248fce5694ba4304f692a5ebeff0bb965e40a2 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Fri, 24 Nov 2017 09:40:40 +0000 Subject: [PATCH] re PR tree-optimization/83128 (Unable to optimize {m,c}alloc when strings builtin are used) 2017-11-24 Richard Biener 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 | 6 ++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-62.c | 11 +++++++++++ gcc/tree-ssa-sccvn.c | 11 ++++++++--- 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-62.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8f34f37b365..cb6c0510535 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-11-24 Richard Biener + + 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 PR sanitizer/83014 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index eef79af85a4..019ff2afc2b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-11-24 Richard Biener + + PR tree-optimization/83128 + * gcc.dg/tree-ssa/ssa-fre-62.c: New testcase. + 2017-11-24 Jakub Jelinek 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 index 00000000000..f02dfe2fa14 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-62.c @@ -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" } } */ diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index d0ff30199e6..63a3db99d03 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -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; -- 2.30.2