re PR tree-optimization/83128 (Unable to optimize {m,c}alloc when strings builtin are used)

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
This commit is contained in:
Richard Biener 2017-11-24 09:40:40 +00:00 committed by Richard Biener
parent 97e1c8786b
commit 6a248fce56
4 changed files with 30 additions and 3 deletions

View 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

View 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

View File

@ -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" } } */

View 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;