re PR tree-optimization/72772 (Missed SCEV after pass reordering@236440)

PR tree-optimization/72772
	* tree-ssa-loop-niter.h (simplify_using_initial_conditions): Delete
	parameter STOP.
	* tree-ssa-loop-niter.c (tree_simplify_using_condition_1): Delete
	parameter STOP and update calls.  Move expand_simple_operations
	function call from here...
	(simplify_using_initial_conditions): ...to here.  Delete parameter
	STOP.
	(tree_simplify_using_condition): Delete parameter STOP.
	* tree-scalar-evolution.c (simple_iv_with_niters): Update call to
	simplify_using_initial_conditions.

From-SVN: r239290
This commit is contained in:
Bin Cheng 2016-08-09 15:01:49 +00:00 committed by Bin Cheng
parent f4fce1837c
commit 8aa46dd2d5
4 changed files with 38 additions and 26 deletions

View file

@ -1,3 +1,17 @@
2016-08-09 Bin Cheng <bin.cheng@arm.com>
PR tree-optimization/72772
* tree-ssa-loop-niter.h (simplify_using_initial_conditions): Delete
parameter STOP.
* tree-ssa-loop-niter.c (tree_simplify_using_condition_1): Delete
parameter STOP and update calls. Move expand_simple_operations
function call from here...
(simplify_using_initial_conditions): ...to here. Delete parameter
STOP.
(tree_simplify_using_condition): Delete parameter STOP.
* tree-scalar-evolution.c (simple_iv_with_niters): Update call to
simplify_using_initial_conditions.
2016-08-09 Matthew Fortune <matthew.fortune@imgtec.com> 2016-08-09 Matthew Fortune <matthew.fortune@imgtec.com>
PR c/65345 PR c/65345

View file

@ -3484,7 +3484,7 @@ simple_iv_with_niters (struct loop *wrto_loop, struct loop *use_loop,
bool allow_nonconstant_step) bool allow_nonconstant_step)
{ {
enum tree_code code; enum tree_code code;
tree type, ev, base, e, stop; tree type, ev, base, e;
wide_int extreme; wide_int extreme;
bool folded_casts, overflow; bool folded_casts, overflow;
@ -3601,8 +3601,7 @@ simple_iv_with_niters (struct loop *wrto_loop, struct loop *use_loop,
return true; return true;
e = fold_build2 (code, boolean_type_node, base, e = fold_build2 (code, boolean_type_node, base,
wide_int_to_tree (type, extreme)); wide_int_to_tree (type, extreme));
stop = (TREE_CODE (base) == SSA_NAME) ? base : NULL; e = simplify_using_initial_conditions (use_loop, e);
e = simplify_using_initial_conditions (use_loop, e, stop);
if (!integer_zerop (e)) if (!integer_zerop (e))
return true; return true;

View file

@ -1939,10 +1939,10 @@ expand_simple_operations (tree expr, tree stop)
expression (or EXPR unchanged, if no simplification was possible). */ expression (or EXPR unchanged, if no simplification was possible). */
static tree static tree
tree_simplify_using_condition_1 (tree cond, tree expr, tree stop) tree_simplify_using_condition_1 (tree cond, tree expr)
{ {
bool changed; bool changed;
tree e, te, e0, e1, e2, notcond; tree e, e0, e1, e2, notcond;
enum tree_code code = TREE_CODE (expr); enum tree_code code = TREE_CODE (expr);
if (code == INTEGER_CST) if (code == INTEGER_CST)
@ -1954,17 +1954,17 @@ tree_simplify_using_condition_1 (tree cond, tree expr, tree stop)
{ {
changed = false; changed = false;
e0 = tree_simplify_using_condition_1 (cond, TREE_OPERAND (expr, 0), stop); e0 = tree_simplify_using_condition_1 (cond, TREE_OPERAND (expr, 0));
if (TREE_OPERAND (expr, 0) != e0) if (TREE_OPERAND (expr, 0) != e0)
changed = true; changed = true;
e1 = tree_simplify_using_condition_1 (cond, TREE_OPERAND (expr, 1), stop); e1 = tree_simplify_using_condition_1 (cond, TREE_OPERAND (expr, 1));
if (TREE_OPERAND (expr, 1) != e1) if (TREE_OPERAND (expr, 1) != e1)
changed = true; changed = true;
if (code == COND_EXPR) if (code == COND_EXPR)
{ {
e2 = tree_simplify_using_condition_1 (cond, TREE_OPERAND (expr, 2), stop); e2 = tree_simplify_using_condition_1 (cond, TREE_OPERAND (expr, 2));
if (TREE_OPERAND (expr, 2) != e2) if (TREE_OPERAND (expr, 2) != e2)
changed = true; changed = true;
} }
@ -2027,16 +2027,14 @@ tree_simplify_using_condition_1 (tree cond, tree expr, tree stop)
return boolean_true_node; return boolean_true_node;
} }
te = expand_simple_operations (expr, stop);
/* Check whether COND ==> EXPR. */ /* Check whether COND ==> EXPR. */
notcond = invert_truthvalue (cond); notcond = invert_truthvalue (cond);
e = fold_binary (TRUTH_OR_EXPR, boolean_type_node, notcond, te); e = fold_binary (TRUTH_OR_EXPR, boolean_type_node, notcond, expr);
if (e && integer_nonzerop (e)) if (e && integer_nonzerop (e))
return e; return e;
/* Check whether COND ==> not EXPR. */ /* Check whether COND ==> not EXPR. */
e = fold_binary (TRUTH_AND_EXPR, boolean_type_node, cond, te); e = fold_binary (TRUTH_AND_EXPR, boolean_type_node, cond, expr);
if (e && integer_zerop (e)) if (e && integer_zerop (e))
return e; return e;
@ -2051,11 +2049,11 @@ tree_simplify_using_condition_1 (tree cond, tree expr, tree stop)
the loop do not cause us to fail. */ the loop do not cause us to fail. */
static tree static tree
tree_simplify_using_condition (tree cond, tree expr, tree stop) tree_simplify_using_condition (tree cond, tree expr)
{ {
cond = expand_simple_operations (cond, stop); cond = expand_simple_operations (cond);
return tree_simplify_using_condition_1 (cond, expr, stop); return tree_simplify_using_condition_1 (cond, expr);
} }
/* Tries to simplify EXPR using the conditions on entry to LOOP. /* Tries to simplify EXPR using the conditions on entry to LOOP.
@ -2063,17 +2061,19 @@ tree_simplify_using_condition (tree cond, tree expr, tree stop)
simplification was possible). */ simplification was possible). */
tree tree
simplify_using_initial_conditions (struct loop *loop, tree expr, tree stop) simplify_using_initial_conditions (struct loop *loop, tree expr)
{ {
edge e; edge e;
basic_block bb; basic_block bb;
gimple *stmt; gimple *stmt;
tree cond; tree cond, expanded, backup;
int cnt = 0; int cnt = 0;
if (TREE_CODE (expr) == INTEGER_CST) if (TREE_CODE (expr) == INTEGER_CST)
return expr; return expr;
backup = expanded = expand_simple_operations (expr);
/* Limit walking the dominators to avoid quadraticness in /* Limit walking the dominators to avoid quadraticness in
the number of BBs times the number of loops in degenerate the number of BBs times the number of loops in degenerate
cases. */ cases. */
@ -2095,15 +2095,17 @@ simplify_using_initial_conditions (struct loop *loop, tree expr, tree stop)
gimple_cond_rhs (stmt)); gimple_cond_rhs (stmt));
if (e->flags & EDGE_FALSE_VALUE) if (e->flags & EDGE_FALSE_VALUE)
cond = invert_truthvalue (cond); cond = invert_truthvalue (cond);
expr = tree_simplify_using_condition (cond, expr, stop); expanded = tree_simplify_using_condition (cond, expanded);
/* Break if EXPR is simplified to const values. */ /* Break if EXPR is simplified to const values. */
if (expr && (integer_zerop (expr) || integer_nonzerop (expr))) if (expanded
break; && (integer_zerop (expanded) || integer_nonzerop (expanded)))
return expanded;
++cnt; ++cnt;
} }
return expr; /* Return the original expression if no simplification is done. */
return operand_equal_p (backup, expanded, 0) ? expr : expanded;
} }
/* Tries to simplify EXPR using the evolutions of the loop invariants /* Tries to simplify EXPR using the evolutions of the loop invariants
@ -4209,8 +4211,6 @@ loop_exits_before_overflow (tree base, tree step,
constant step because otherwise we don't have the information. */ constant step because otherwise we don't have the information. */
if (TREE_CODE (step) == INTEGER_CST) if (TREE_CODE (step) == INTEGER_CST)
{ {
tree stop = (TREE_CODE (base) == SSA_NAME) ? base : NULL;
for (civ = loop->control_ivs; civ; civ = civ->next) for (civ = loop->control_ivs; civ; civ = civ->next)
{ {
enum tree_code code; enum tree_code code;
@ -4268,7 +4268,7 @@ loop_exits_before_overflow (tree base, tree step,
} }
extreme = fold_build2 (MINUS_EXPR, type, extreme, step); extreme = fold_build2 (MINUS_EXPR, type, extreme, step);
e = fold_build2 (code, boolean_type_node, base, extreme); e = fold_build2 (code, boolean_type_node, base, extreme);
e = simplify_using_initial_conditions (loop, e, stop); e = simplify_using_initial_conditions (loop, e);
if (integer_zerop (e)) if (integer_zerop (e))
return true; return true;
} }

View file

@ -21,8 +21,7 @@ along with GCC; see the file COPYING3. If not see
#define GCC_TREE_SSA_LOOP_NITER_H #define GCC_TREE_SSA_LOOP_NITER_H
extern tree expand_simple_operations (tree, tree = NULL); extern tree expand_simple_operations (tree, tree = NULL);
extern tree simplify_using_initial_conditions (struct loop *, extern tree simplify_using_initial_conditions (struct loop *, tree);
tree, tree = NULL);
extern bool loop_only_exit_p (const struct loop *, const_edge); extern bool loop_only_exit_p (const struct loop *, const_edge);
extern bool number_of_iterations_exit (struct loop *, edge, extern bool number_of_iterations_exit (struct loop *, edge,
struct tree_niter_desc *niter, bool, struct tree_niter_desc *niter, bool,