Commit c0aae19c by Richard Guenther Committed by Richard Biener

re PR tree-optimization/47621 (Missed dependencies in address-taken optimization)

2011-02-07  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/47621
	* tree-ssa.c (non_rewritable_lvalue_p): New function, split out from
	two duplicates ...
	(execute_update_addresses_taken): ... here.  Make it more
	conservative in what we accept.

	* gcc.dg/torture/pr47621.c: New testcase.

From-SVN: r169881
parent e6d926d7
2011-02-07 Richard Guenther <rguenther@suse.de>
PR tree-optimization/47621
* tree-ssa.c (non_rewritable_lvalue_p): New function, split out from
two duplicates ...
(execute_update_addresses_taken): ... here. Make it more
conservative in what we accept.
2011-02-06 Joseph Myers <joseph@codesourcery.com> 2011-02-06 Joseph Myers <joseph@codesourcery.com>
* config/sparc/freebsd.h (ASM_SPEC): Define. * config/sparc/freebsd.h (ASM_SPEC): Define.
......
2011-02-07 Richard Guenther <rguenther@suse.de>
PR tree-optimization/47621
* gcc.dg/torture/pr47621.c: New testcase.
2011-02-07 Uros Bizjak <ubizjak@gmail.com> 2011-02-07 Uros Bizjak <ubizjak@gmail.com>
* gfortran.dg/transpose_optimization_2.f90: Cleanup original dump. * gfortran.dg/transpose_optimization_2.f90: Cleanup original dump.
......
/* { dg-do run } */
extern void abort (void);
int
main (void)
{
int data = 1;
struct ptr { int val; } *ptr = (struct ptr *) &data;
ptr->val = 0;
if (data != 0)
abort ();
return 0;
}
...@@ -1885,6 +1885,34 @@ non_rewritable_mem_ref_base (tree ref) ...@@ -1885,6 +1885,34 @@ non_rewritable_mem_ref_base (tree ref)
return NULL_TREE; return NULL_TREE;
} }
/* For an lvalue tree LHS return true if it cannot be rewritten into SSA form.
Otherwise return true. */
static bool
non_rewritable_lvalue_p (tree lhs)
{
/* A plain decl is always rewritable. */
if (DECL_P (lhs))
return false;
/* A decl that is wrapped inside a MEM-REF that covers
it full is also rewritable.
??? The following could be relaxed allowing component
references that do not change the access size. */ ;
if (TREE_CODE (lhs) == MEM_REF
&& TREE_CODE (TREE_OPERAND (lhs, 0)) == ADDR_EXPR
&& integer_zerop (TREE_OPERAND (lhs, 1)))
{
tree decl = TREE_OPERAND (TREE_OPERAND (lhs, 0), 0);
if (DECL_P (decl)
&& DECL_SIZE (decl) == TYPE_SIZE (TREE_TYPE (lhs))
&& (TREE_THIS_VOLATILE (decl) == TREE_THIS_VOLATILE (lhs)))
return false;
}
return true;
}
/* When possible, clear TREE_ADDRESSABLE bit or set DECL_GIMPLE_REG_P bit and /* When possible, clear TREE_ADDRESSABLE bit or set DECL_GIMPLE_REG_P bit and
mark the variable VAR for conversion into SSA. Return true when updating mark the variable VAR for conversion into SSA. Return true when updating
stmts is required. */ stmts is required. */
...@@ -1978,31 +2006,15 @@ execute_update_addresses_taken (void) ...@@ -1978,31 +2006,15 @@ execute_update_addresses_taken (void)
if (code == GIMPLE_ASSIGN || code == GIMPLE_CALL) if (code == GIMPLE_ASSIGN || code == GIMPLE_CALL)
{ {
tree lhs = gimple_get_lhs (stmt); tree lhs = gimple_get_lhs (stmt);
if (lhs
/* A plain decl does not need it set. */ && TREE_CODE (lhs) != SSA_NAME
if (lhs && !DECL_P (lhs)) && non_rewritable_lvalue_p (lhs))
{ {
tree orig_lhs = lhs; decl = get_base_address (lhs);
if (DECL_P (decl))
while (handled_component_p (lhs))
lhs = TREE_OPERAND (lhs, 0);
if (DECL_P (lhs))
bitmap_set_bit (not_reg_needs, DECL_UID (lhs));
else if (TREE_CODE (lhs) == MEM_REF
&& TREE_CODE (TREE_OPERAND (lhs, 0)) == ADDR_EXPR)
{
decl = TREE_OPERAND (TREE_OPERAND (lhs, 0), 0);
if (DECL_P (decl)
&& (!integer_zerop (TREE_OPERAND (lhs, 1))
|| (DECL_SIZE (decl)
!= TYPE_SIZE (TREE_TYPE (orig_lhs)))
|| (TREE_THIS_VOLATILE (lhs)
!= TREE_THIS_VOLATILE (decl))))
bitmap_set_bit (not_reg_needs, DECL_UID (decl)); bitmap_set_bit (not_reg_needs, DECL_UID (decl));
} }
} }
}
if (gimple_assign_single_p (stmt)) if (gimple_assign_single_p (stmt))
{ {
...@@ -2027,31 +2039,14 @@ execute_update_addresses_taken (void) ...@@ -2027,31 +2039,14 @@ execute_update_addresses_taken (void)
{ {
tree link = gimple_asm_output_op (stmt, i); tree link = gimple_asm_output_op (stmt, i);
tree lhs = TREE_VALUE (link); tree lhs = TREE_VALUE (link);
if (TREE_CODE (lhs) != SSA_NAME
/* A plain decl does not need it set. */ && non_rewritable_lvalue_p (lhs))
if (!DECL_P (lhs))
{
tree orig_lhs = lhs;
while (handled_component_p (lhs))
lhs = TREE_OPERAND (lhs, 0);
if (DECL_P (lhs))
bitmap_set_bit (not_reg_needs, DECL_UID (lhs));
else if (TREE_CODE (lhs) == MEM_REF
&& TREE_CODE (TREE_OPERAND (lhs, 0)) == ADDR_EXPR)
{ {
decl = TREE_OPERAND (TREE_OPERAND (lhs, 0), 0); decl = get_base_address (lhs);
if (DECL_P (decl) if (DECL_P (decl))
&& (!integer_zerop (TREE_OPERAND (lhs, 1))
|| (TYPE_MAIN_VARIANT (TREE_TYPE (decl))
!= TYPE_MAIN_VARIANT (TREE_TYPE (orig_lhs)))
|| (TREE_THIS_VOLATILE (lhs)
!= TREE_THIS_VOLATILE (decl))))
bitmap_set_bit (not_reg_needs, DECL_UID (decl)); bitmap_set_bit (not_reg_needs, DECL_UID (decl));
} }
} }
}
for (i = 0; i < gimple_asm_ninputs (stmt); ++i) for (i = 0; i < gimple_asm_ninputs (stmt); ++i)
{ {
tree link = gimple_asm_input_op (stmt, i); tree link = gimple_asm_input_op (stmt, i);
......
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