Commit e1fd038a by Sebastian Pop Committed by Sebastian Pop

Do not check whether memory references accessed in every iteration trap.

This patch relaxes the checks from gimple_could_trap_p in order to
allow the flag_loop_if_convert_stores to if-convert more loops
in which it is possible to prove that:

- the accesses to an array in a loop do not trap (more than the
  original non-if-converted loop).  This is true when the memory
  accesses are executed at every iteration of the if-converted loop.

- the writes to memory occur on arrays that are not const qualified.
  This is true when there exists at least one unconditional write to
  the array in the analyzed program.  In this patch this analysis is
  limited to the loop to be if-converted.

	* gimple.c (gimple_could_trap_p_1): Not static anymore.
	Pass an extra bool parameter include_mem.
	(gimple_could_trap_p): Adjust call to gimple_could_trap_p_1.
	(gimple_assign_rhs_could_trap_p): Same.
	* gimple.h (gimple_could_trap_p_1): Declared.
	* tree-data-ref.h (same_data_refs_base_objects): New.
	(same_data_refs): New.
	* tree-if-conv.c (memrefs_read_or_written_unconditionally): New.
	(write_memrefs_written_at_least_once): New.
	(ifcvt_memrefs_wont_trap): New.
	(operations_could_trap): New.
	(ifcvt_could_trap_p): New.
	(if_convertible_gimple_assign_stmt_p): Call ifcvt_could_trap_p.
	Gets a vector of data refs.
	(if_convertible_stmt_p): Same.
	(if_convertible_loop_p_1): New.
	(if_convertible_loop_p): Call if_convertible_loop_p_1.

	* gcc.dg/tree-ssa/ifc-5.c: New.

From-SVN: r163531
parent bd544141
2010-08-24 Sebastian Pop <sebastian.pop@amd.com>
* gimple.c (gimple_could_trap_p_1): Not static anymore.
Pass an extra bool parameter include_mem.
(gimple_could_trap_p): Adjust call to gimple_could_trap_p_1.
(gimple_assign_rhs_could_trap_p): Same.
* gimple.h (gimple_could_trap_p_1): Declared.
* tree-data-ref.h (same_data_refs_base_objects): New.
(same_data_refs): New.
* tree-if-conv.c (memrefs_read_or_written_unconditionally): New.
(write_memrefs_written_at_least_once): New.
(ifcvt_memrefs_wont_trap): New.
(operations_could_trap): New.
(ifcvt_could_trap_p): New.
(if_convertible_gimple_assign_stmt_p): Call ifcvt_could_trap_p.
Gets a vector of data refs.
(if_convertible_stmt_p): Same.
(if_convertible_loop_p_1): New.
(if_convertible_loop_p): Call if_convertible_loop_p_1.
2010-08-24 Sebastian Pop <sebastian.pop@amd.com>
* common.opt (ftree-loop-if-convert-stores): New flag.
* doc/invoke.texi (ftree-loop-if-convert-stores): Documented.
* tree-if-conv.c (ifc_temp_var): Pass an extra parameter GSI. Insert
......
......@@ -2399,24 +2399,25 @@ gimple_rhs_has_side_effects (const_gimple s)
return false;
}
/* Helper for gimple_could_trap_p and gimple_assign_rhs_could_trap_p.
Return true if S can trap. If INCLUDE_LHS is true and S is a
GIMPLE_ASSIGN, the LHS of the assignment is also checked.
Otherwise, only the RHS of the assignment is checked. */
Return true if S can trap. When INCLUDE_MEM is true, check whether
the memory operations could trap. When INCLUDE_STORES is true and
S is a GIMPLE_ASSIGN, the LHS of the assignment is also checked. */
static bool
gimple_could_trap_p_1 (gimple s, bool include_lhs)
bool
gimple_could_trap_p_1 (gimple s, bool include_mem, bool include_stores)
{
unsigned i, start;
tree t, div = NULL_TREE;
enum tree_code op;
start = (is_gimple_assign (s) && !include_lhs) ? 1 : 0;
if (include_mem)
{
unsigned i, start = (is_gimple_assign (s) && !include_stores) ? 1 : 0;
for (i = start; i < gimple_num_ops (s); i++)
if (tree_could_trap_p (gimple_op (s, i)))
return true;
}
switch (gimple_code (s))
{
......@@ -2445,26 +2446,23 @@ gimple_could_trap_p_1 (gimple s, bool include_lhs)
}
return false;
}
/* Return true if statement S can trap. */
bool
gimple_could_trap_p (gimple s)
{
return gimple_could_trap_p_1 (s, true);
return gimple_could_trap_p_1 (s, true, true);
}
/* Return true if RHS of a GIMPLE_ASSIGN S can trap. */
bool
gimple_assign_rhs_could_trap_p (gimple s)
{
gcc_assert (is_gimple_assign (s));
return gimple_could_trap_p_1 (s, false);
return gimple_could_trap_p_1 (s, true, false);
}
......
......@@ -886,6 +886,7 @@ void gimple_cond_set_condition_from_tree (gimple, tree);
bool gimple_has_side_effects (const_gimple);
bool gimple_rhs_has_side_effects (const_gimple);
bool gimple_could_trap_p (gimple);
bool gimple_could_trap_p_1 (gimple, bool, bool);
bool gimple_assign_rhs_could_trap_p (gimple);
void gimple_regimplify_operands (gimple, gimple_stmt_iterator *);
bool empty_body_p (gimple_seq);
......
2010-08-24 Sebastian Pop <sebastian.pop@amd.com>
* gcc.dg/tree-ssa/ifc-5.c: New.
2010-08-24 Sebastian Pop <sebastian.pop@amd.com>
* gcc.dg/tree-ssa/ifc-4.c: New.
* gcc.dg/tree-ssa/ifc-7.c: New.
......
/* { dg-do compile } */
/* { dg-options "-c -O2 -ftree-vectorize -fdump-tree-ifcvt-stats" { target *-*-* } } */
void
dct_unquantize_h263_inter_c (short *block, int n, int qscale, int nCoeffs)
{
int i, level, qmul, qadd;
qadd = (qscale - 1) | 1;
qmul = qscale << 1;
for (i = 0; i <= nCoeffs; i++)
{
level = block[i];
if (level < 0)
level = level * qmul - qadd;
else
level = level * qmul + qadd;
block[i] = level;
}
}
/* { dg-final { scan-tree-dump-times "Applying if-conversion" 1 "ifcvt" } } */
/* { dg-final { cleanup-tree-dump "ifcvt" } } */
......@@ -417,6 +417,39 @@ extern void create_rdg_vertices (struct graph *, VEC (gimple, heap) *);
extern bool dr_may_alias_p (const struct data_reference *,
const struct data_reference *);
/* Return true when the base objects of data references A and B are
the same memory object. */
static inline bool
same_data_refs_base_objects (data_reference_p a, data_reference_p b)
{
return DR_NUM_DIMENSIONS (a) == DR_NUM_DIMENSIONS (b)
&& operand_equal_p (DR_BASE_OBJECT (a), DR_BASE_OBJECT (b), 0);
}
/* Return true when the data references A and B are accessing the same
memory object with the same access functions. */
static inline bool
same_data_refs (data_reference_p a, data_reference_p b)
{
unsigned int i;
/* The references are exactly the same. */
if (operand_equal_p (DR_REF (a), DR_REF (b), 0))
return true;
if (!same_data_refs_base_objects (a, b))
return false;
for (i = 0; i < DR_NUM_DIMENSIONS (a); i++)
if (!eq_evolutions_p (DR_ACCESS_FN (a, i), DR_ACCESS_FN (b, i)))
return false;
return true;
}
/* Return true when the DDR contains two data references that have the
same access functions. */
......
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