Commit e2abde5f by Richard Guenther Committed by Richard Biener

builtins.c (fold_builtin_memory_op): Use the alias oracle to query if the memory…

builtins.c (fold_builtin_memory_op): Use the alias oracle to query if the memory regions for memmove overlap.

2009-08-31  Richard Guenther  <rguenther@suse.de>

	* builtins.c (fold_builtin_memory_op): Use the alias oracle
	to query if the memory regions for memmove overlap.
	* tree-ssa-alias.c (ptr_deref_may_alias_decl_p): Relax the
	asserts on pointers, instead deal with odd trees.
	(ptr_derefs_may_alias_p): Likewise.
	(refs_may_alias_p_1): Constructor bases also never alias.

From-SVN: r151241
parent 2fbd4117
2009-08-31 Richard Guenther <rguenther@suse.de>
* builtins.c (fold_builtin_memory_op): Use the alias oracle
to query if the memory regions for memmove overlap.
* tree-ssa-alias.c (ptr_deref_may_alias_decl_p): Relax the
asserts on pointers, instead deal with odd trees.
(ptr_derefs_may_alias_p): Likewise.
(refs_may_alias_p_1): Constructor bases also never alias.
2009-08-31 Gerald Pfeifer <gerald@pfeifer.com> 2009-08-31 Gerald Pfeifer <gerald@pfeifer.com>
* doc/install.texi (Final install): Adjust reference on where to * doc/install.texi (Final install): Adjust reference on where to
......
...@@ -8990,6 +8990,8 @@ fold_builtin_memory_op (location_t loc, tree dest, tree src, ...@@ -8990,6 +8990,8 @@ fold_builtin_memory_op (location_t loc, tree dest, tree src,
if (endp == 3) if (endp == 3)
{ {
ao_ref srcref, destref;
src_align = get_pointer_alignment (src, BIGGEST_ALIGNMENT); src_align = get_pointer_alignment (src, BIGGEST_ALIGNMENT);
dest_align = get_pointer_alignment (dest, BIGGEST_ALIGNMENT); dest_align = get_pointer_alignment (dest, BIGGEST_ALIGNMENT);
...@@ -9012,62 +9014,16 @@ fold_builtin_memory_op (location_t loc, tree dest, tree src, ...@@ -9012,62 +9014,16 @@ fold_builtin_memory_op (location_t loc, tree dest, tree src,
} }
/* If *src and *dest can't overlap, optimize into memcpy as well. */ /* If *src and *dest can't overlap, optimize into memcpy as well. */
srcvar = build_fold_indirect_ref_loc (loc, src); ao_ref_init_from_ptr_and_size (&srcref, src, len);
destvar = build_fold_indirect_ref_loc (loc, dest); ao_ref_init_from_ptr_and_size (&destref, dest, len);
if (srcvar if (!refs_may_alias_p_1 (&srcref, &destref, false))
&& !TREE_THIS_VOLATILE (srcvar)
&& destvar
&& !TREE_THIS_VOLATILE (destvar))
{
tree src_base, dest_base, fn;
HOST_WIDE_INT src_offset = 0, dest_offset = 0;
HOST_WIDE_INT size = -1;
HOST_WIDE_INT maxsize = -1;
src_base = srcvar;
if (handled_component_p (src_base))
src_base = get_ref_base_and_extent (src_base, &src_offset,
&size, &maxsize);
dest_base = destvar;
if (handled_component_p (dest_base))
dest_base = get_ref_base_and_extent (dest_base, &dest_offset,
&size, &maxsize);
if (host_integerp (len, 1))
{
maxsize = tree_low_cst (len, 1);
if (maxsize
> INTTYPE_MAXIMUM (HOST_WIDE_INT) / BITS_PER_UNIT)
maxsize = -1;
else
maxsize *= BITS_PER_UNIT;
}
else
maxsize = -1;
if (SSA_VAR_P (src_base)
&& SSA_VAR_P (dest_base))
{
if (operand_equal_p (src_base, dest_base, 0)
&& ranges_overlap_p (src_offset, maxsize,
dest_offset, maxsize))
return NULL_TREE;
}
else if (TREE_CODE (src_base) == INDIRECT_REF
&& TREE_CODE (dest_base) == INDIRECT_REF)
{ {
if (! operand_equal_p (TREE_OPERAND (src_base, 0), tree fn = implicit_built_in_decls[BUILT_IN_MEMCPY];
TREE_OPERAND (dest_base, 0), 0)
|| ranges_overlap_p (src_offset, maxsize,
dest_offset, maxsize))
return NULL_TREE;
}
else
return NULL_TREE;
fn = implicit_built_in_decls[BUILT_IN_MEMCPY];
if (!fn) if (!fn)
return NULL_TREE; return NULL_TREE;
return build_call_expr_loc (loc, fn, 3, dest, src, len); return build_call_expr_loc (loc, fn, 3, dest, src, len);
} }
return NULL_TREE; return NULL_TREE;
} }
......
...@@ -168,12 +168,9 @@ ptr_deref_may_alias_decl_p (tree ptr, tree decl) ...@@ -168,12 +168,9 @@ ptr_deref_may_alias_decl_p (tree ptr, tree decl)
{ {
struct ptr_info_def *pi; struct ptr_info_def *pi;
gcc_assert ((TREE_CODE (ptr) == SSA_NAME gcc_assert (TREE_CODE (decl) == VAR_DECL
|| TREE_CODE (ptr) == ADDR_EXPR
|| TREE_CODE (ptr) == INTEGER_CST)
&& (TREE_CODE (decl) == VAR_DECL
|| TREE_CODE (decl) == PARM_DECL || TREE_CODE (decl) == PARM_DECL
|| TREE_CODE (decl) == RESULT_DECL)); || TREE_CODE (decl) == RESULT_DECL);
/* Non-aliased variables can not be pointed to. */ /* Non-aliased variables can not be pointed to. */
if (!may_be_aliased (decl)) if (!may_be_aliased (decl))
...@@ -197,9 +194,9 @@ ptr_deref_may_alias_decl_p (tree ptr, tree decl) ...@@ -197,9 +194,9 @@ ptr_deref_may_alias_decl_p (tree ptr, tree decl)
return true; return true;
} }
/* We can end up with dereferencing constant pointers. /* We can end up with dereferencing non-SSA name pointers.
Just bail out in this case. */ Just bail out in this case. */
if (TREE_CODE (ptr) == INTEGER_CST) if (TREE_CODE (ptr) != SSA_NAME)
return true; return true;
/* If we do not have useful points-to information for this pointer /* If we do not have useful points-to information for this pointer
...@@ -220,13 +217,6 @@ ptr_derefs_may_alias_p (tree ptr1, tree ptr2) ...@@ -220,13 +217,6 @@ ptr_derefs_may_alias_p (tree ptr1, tree ptr2)
{ {
struct ptr_info_def *pi1, *pi2; struct ptr_info_def *pi1, *pi2;
gcc_assert ((TREE_CODE (ptr1) == SSA_NAME
|| TREE_CODE (ptr1) == ADDR_EXPR
|| TREE_CODE (ptr1) == INTEGER_CST)
&& (TREE_CODE (ptr2) == SSA_NAME
|| TREE_CODE (ptr2) == ADDR_EXPR
|| TREE_CODE (ptr2) == INTEGER_CST));
/* ADDR_EXPR pointers either just offset another pointer or directly /* ADDR_EXPR pointers either just offset another pointer or directly
specify the pointed-to set. */ specify the pointed-to set. */
if (TREE_CODE (ptr1) == ADDR_EXPR) if (TREE_CODE (ptr1) == ADDR_EXPR)
...@@ -254,10 +244,10 @@ ptr_derefs_may_alias_p (tree ptr1, tree ptr2) ...@@ -254,10 +244,10 @@ ptr_derefs_may_alias_p (tree ptr1, tree ptr2)
return true; return true;
} }
/* We can end up with dereferencing constant pointers. /* We can end up with dereferencing non-SSA name pointers.
Just bail out in this case. */ Just bail out in this case. */
if (TREE_CODE (ptr1) == INTEGER_CST if (TREE_CODE (ptr1) != SSA_NAME
|| TREE_CODE (ptr2) == INTEGER_CST) || TREE_CODE (ptr2) != SSA_NAME)
return true; return true;
/* We may end up with two empty points-to solutions for two same pointers. /* We may end up with two empty points-to solutions for two same pointers.
...@@ -781,7 +771,9 @@ refs_may_alias_p_1 (ao_ref *ref1, ao_ref *ref2, bool tbaa_p) ...@@ -781,7 +771,9 @@ refs_may_alias_p_1 (ao_ref *ref1, ao_ref *ref2, bool tbaa_p)
if (TREE_CODE (base1) == SSA_NAME if (TREE_CODE (base1) == SSA_NAME
|| TREE_CODE (base2) == SSA_NAME || TREE_CODE (base2) == SSA_NAME
|| is_gimple_min_invariant (base1) || is_gimple_min_invariant (base1)
|| is_gimple_min_invariant (base2)) || is_gimple_min_invariant (base2)
|| TREE_CODE (base1) == CONSTRUCTOR
|| TREE_CODE (base2) == CONSTRUCTOR)
return false; return false;
/* Defer to simple offset based disambiguation if we have /* Defer to simple offset based disambiguation if we have
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment