Commit bd544141 by Sebastian Pop Committed by Sebastian Pop

Add flag -ftree-loop-if-convert-stores.

This patch adds a flag that controls the replacement of the memory
writes that are in predicated basic blocks with a full write:

for (...)
  if (cond)
    A[i] = foo

is replaced with:

for (...)
  A[i] = cond ? foo : A[i]

In order to do this, we have to call gimple_could_trap_p instead of
gimple_assign_rhs_could_trap_p, as we have to also check that the LHS
of assign stmts does not trap.

	* 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
	the created statement before GSI.
	(if_convertible_phi_p): Allow virtual phi nodes when
	flag_loop_if_convert_stores is set.
	(if_convertible_gimple_assign_stmt_p): Allow memory reads and writes
	Do not handle types that do not match is_gimple_reg_type.
	Remove loop and bb parameters.  Call gimple_could_trap_p instead of
	when flag_loop_if_convert_stores is set, as LHS can contain
	memory refs.
	(if_convertible_stmt_p): Remove loop and bb parameters.  Update calls
	to if_convertible_gimple_assign_stmt_p.
	(if_convertible_loop_p): Update call to if_convertible_stmt_p.
	(replace_phi_with_cond_gimple_assign_stmt): Renamed
	predicate_scalar_phi.  Do not handle virtual phi nodes.
	(ifconvert_phi_nodes): Renamed predicate_all_scalar_phis.
	Call predicate_scalar_phi.
	(insert_gimplified_predicates): Insert the gimplified predicate of a BB
	just after the labels for flag_loop_if_convert_stores, otherwise
	insert the predicate in the end of the BB.
	(predicate_mem_writes): New.
	(combine_blocks): Call predicate_all_scalar_phis.  When
	flag_loop_if_convert_stores is set, call predicate_mem_writes.
	(tree_if_conversion): Call mark_sym_for_renaming when
	flag_loop_if_convert_stores is set.
	(main_tree_if_conversion): Return TODO_update_ssa_only_virtuals when
	flag_loop_if_convert_stores is set.

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

From-SVN: r163530
parent 3a9abc98
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
the created statement before GSI.
(if_convertible_phi_p): Allow virtual phi nodes when
flag_loop_if_convert_stores is set.
(if_convertible_gimple_assign_stmt_p): Allow memory reads and writes
Do not handle types that do not match is_gimple_reg_type.
Remove loop and bb parameters. Call gimple_could_trap_p instead of
when flag_loop_if_convert_stores is set, as LHS can contain
memory refs.
(if_convertible_stmt_p): Remove loop and bb parameters. Update calls
to if_convertible_gimple_assign_stmt_p.
(if_convertible_loop_p): Update call to if_convertible_stmt_p.
(replace_phi_with_cond_gimple_assign_stmt): Renamed
predicate_scalar_phi. Do not handle virtual phi nodes.
(ifconvert_phi_nodes): Renamed predicate_all_scalar_phis.
Call predicate_scalar_phi.
(insert_gimplified_predicates): Insert the gimplified predicate of a BB
just after the labels for flag_loop_if_convert_stores, otherwise
insert the predicate in the end of the BB.
(predicate_mem_writes): New.
(combine_blocks): Call predicate_all_scalar_phis. When
flag_loop_if_convert_stores is set, call predicate_mem_writes.
(tree_if_conversion): Call mark_sym_for_renaming when
flag_loop_if_convert_stores is set.
(main_tree_if_conversion): Return TODO_update_ssa_only_virtuals when
flag_loop_if_convert_stores is set.
2010-08-24 Anatoly Sokolov <aesok@post.ru>
* config/pa/pa.c (hppa_register_move_cost, pa_libcall_value,
......
......@@ -712,6 +712,10 @@ ftree-loop-if-convert
Common Report Var(flag_tree_loop_if_convert) Init(-1) Optimization
Convert conditional jumps in innermost loops to branchless equivalents
ftree-loop-if-convert-stores
Common Report Var(flag_tree_loop_if_convert_stores) Optimization
Also if-convert conditional jumps containing memory writes
; -finhibit-size-directive inhibits output of .size for ELF.
; This is used only for compiling crtstuff.c,
; and it may be extended to other effects
......
......@@ -383,7 +383,8 @@ Objective-C and Objective-C++ Dialects}.
-fstrict-aliasing -fstrict-overflow -fthread-jumps -ftracer -ftree-bit-ccp @gol
-ftree-builtin-call-dce -ftree-ccp -ftree-ch -ftree-copy-prop @gol
-ftree-copyrename -ftree-dce -ftree-dominator-opts -ftree-dse @gol
-ftree-forwprop -ftree-fre -ftree-loop-if-convert -ftree-loop-im @gol
-ftree-forwprop -ftree-fre -ftree-loop-if-convert @gol
-ftree-loop-if-convert-memory-writes -ftree-loop-im @gol
-ftree-phiprop -ftree-loop-distribution -ftree-loop-distribute-patterns @gol
-ftree-loop-ivcanon -ftree-loop-linear -ftree-loop-optimize @gol
-ftree-parallelize-loops=@var{n} -ftree-pre -ftree-pta -ftree-reassoc @gol
......@@ -6931,6 +6932,23 @@ the innermost loops in order to improve the ability of the
vectorization pass to handle these loops. This is enabled by default
if vectorization is enabled.
@item -ftree-loop-if-convert-stores
Attempt to also if-convert conditional jumps containing memory writes.
This transformation can be unsafe for multi-threaded programs as it
transforms conditional memory writes into unconditional memory writes.
For example,
@smallexample
for (i = 0; i < N; i++)
if (cond)
A[i] = expr;
@end smallexample
would be transformed to
@smallexample
for (i = 0; i < N; i++)
A[i] = cond ? expr : A[i];
@end smallexample
potentially producing data races.
@item -ftree-loop-distribution
Perform loop distribution. This flag can improve cache performance on
big loop bodies and allow further loop optimizations, like
......
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.
2010-08-24 Mingjie Xing <mingjie.xing@gmail.com>
* gcc.dg/vect/vect.exp: Check loongson targets
......
/* { dg-do compile } */
/* { dg-options "-c -O2 -ftree-vectorize -fdump-tree-ifcvt-stats" { target *-*-* } } */
struct ht
{
void * (*alloc_subobject) (int);
};
typedef struct cpp_reader cpp_reader;
typedef struct cpp_token cpp_token;
typedef struct cpp_macro cpp_macro;
enum cpp_ttype
{
CPP_PASTE,
};
struct cpp_token {
__extension__ enum cpp_ttype type : 8;
} cpp_comment_table;
struct cpp_macro {
union cpp_macro_u
{
cpp_token * tokens;
} exp;
unsigned int count;
};
struct cpp_reader
{
struct ht *hash_table;
};
create_iso_definition (cpp_reader *pfile, cpp_macro *macro)
{
unsigned int num_extra_tokens = 0;
{
cpp_token *tokns =
(cpp_token *) pfile->hash_table->alloc_subobject (sizeof (cpp_token)
* macro->count);
{
cpp_token *normal_dest = tokns;
cpp_token *extra_dest = tokns + macro->count - num_extra_tokens;
unsigned int i;
for (i = 0; i < macro->count; i++)
{
if (macro->exp.tokens[i].type == CPP_PASTE)
*extra_dest++ = macro->exp.tokens[i];
else
*normal_dest++ = macro->exp.tokens[i];
}
}
}
}
/* This cannot be if-converted because the stores are to aggregate types. */
/* { dg-final { scan-tree-dump-times "Applying if-conversion" 0 "ifcvt" } } */
/* { dg-final { cleanup-tree-dump "ifcvt" } } */
/* { dg-do compile } */
/* { dg-options "-c -O2 -ftree-vectorize" { target *-*-* } } */
typedef struct eqn_d
{
int *coef;
} *eqn;
typedef struct omega_pb_d
{
eqn subs;
} *omega_pb;
omega_pb omega_solve_problem (omega_pb);
omega_pb
omega_solve_geq (omega_pb pb, int n)
{
int i, e;
int j = 0;
for (e = n - 1; e >= 0; e--)
if (pb->subs[e].coef[i] != pb->subs[e].coef[j])
{
pb->subs[e].coef[i] = j;
pb->subs[e].coef[j] = i;
}
return omega_solve_problem (pb);
}
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