/* Array to record value-handles per SSA_NAME. */
vec<tree> ssa_name_values;
-typedef tree (pfn_simplify) (gimple *, gimple *, class avail_exprs_stack *);
+typedef tree (pfn_simplify) (gimple *, gimple *,
+ class avail_exprs_stack *,
+ basic_block);
/* Set the value for the SSA name NAME to VALUE. */
return true;
}
-/* Return the LHS of any ASSERT_EXPR where OP appears as the first
- argument to the ASSERT_EXPR and in which the ASSERT_EXPR dominates
- BB. If no such ASSERT_EXPR is found, return OP. */
-
-static tree
-lhs_of_dominating_assert (tree op, basic_block bb, gimple *stmt)
-{
- imm_use_iterator imm_iter;
- gimple *use_stmt;
- use_operand_p use_p;
-
- FOR_EACH_IMM_USE_FAST (use_p, imm_iter, op)
- {
- use_stmt = USE_STMT (use_p);
- if (use_stmt != stmt
- && gimple_assign_single_p (use_stmt)
- && TREE_CODE (gimple_assign_rhs1 (use_stmt)) == ASSERT_EXPR
- && TREE_OPERAND (gimple_assign_rhs1 (use_stmt), 0) == op
- && dominated_by_p (CDI_DOMINATORS, bb, gimple_bb (use_stmt)))
- {
- return gimple_assign_lhs (use_stmt);
- }
- }
- return op;
-}
-
/* Record temporary equivalences created by PHIs at the target of the
edge E. Record unwind information for the equivalences onto STACK.
SET_USE (use_p, tmp);
}
- cached_lhs = (*simplify) (stmt, stmt, avail_exprs_stack);
+ cached_lhs = (*simplify) (stmt, stmt, avail_exprs_stack, e->src);
/* Restore the statement's original uses/defs. */
i = 0;
static tree simplify_control_stmt_condition_1 (edge, gimple *,
class avail_exprs_stack *,
tree, enum tree_code, tree,
- gcond *, pfn_simplify, bool,
+ gcond *, pfn_simplify,
unsigned);
/* Simplify the control statement at the end of the block E->dest.
gimple *stmt,
class avail_exprs_stack *avail_exprs_stack,
gcond *dummy_cond,
- pfn_simplify simplify,
- bool handle_dominating_asserts)
+ pfn_simplify simplify)
{
tree cond, cached_lhs;
enum gimple_code code = gimple_code (stmt);
= simplify_control_stmt_condition_1 (e, stmt, avail_exprs_stack,
op0, cond_code, op1,
dummy_cond, simplify,
- handle_dominating_asserts,
recursion_limit);
/* If we were testing an integer/pointer against a constant, then
}
}
- /* If we're dominated by a suitable ASSERT_EXPR, then
- update CACHED_LHS appropriately. */
- if (handle_dominating_asserts && TREE_CODE (cached_lhs) == SSA_NAME)
- cached_lhs = lhs_of_dominating_assert (cached_lhs, e->src, stmt);
-
/* If we haven't simplified to an invariant yet, then use the
pass specific callback to try and simplify it further. */
if (cached_lhs && ! is_gimple_min_invariant (cached_lhs))
{
- if (handle_dominating_asserts && code == GIMPLE_SWITCH)
+ if (code == GIMPLE_SWITCH)
{
- /* Replace the index operand of the GIMPLE_SWITCH with the
- dominating ASSERT_EXPR before handing it off to VRP. If
- simplification is possible, the simplified value will be a
- CASE_LABEL_EXPR of the label that is proven to be taken. */
+ /* Replace the index operand of the GIMPLE_SWITCH with any LHS
+ we found before handing off to VRP. If simplification is
+ possible, the simplified value will be a CASE_LABEL_EXPR of
+ the label that is proven to be taken. */
gswitch *dummy_switch = as_a<gswitch *> (gimple_copy (stmt));
gimple_switch_set_index (dummy_switch, cached_lhs);
- cached_lhs = (*simplify) (dummy_switch, stmt, avail_exprs_stack);
+ cached_lhs = (*simplify) (dummy_switch, stmt,
+ avail_exprs_stack, e->src);
ggc_free (dummy_switch);
}
else
- cached_lhs = (*simplify) (stmt, stmt, avail_exprs_stack);
+ cached_lhs = (*simplify) (stmt, stmt, avail_exprs_stack, e->src);
}
/* We couldn't find an invariant. But, callers of this
tree op1,
gcond *dummy_cond,
pfn_simplify simplify,
- bool handle_dominating_asserts,
unsigned limit)
{
if (limit == 0)
recurse into the LHS to see if there is a dominating ASSERT_EXPR
of A or of B that makes this condition always true or always false
along the edge E. */
- if (handle_dominating_asserts
- && (cond_code == EQ_EXPR || cond_code == NE_EXPR)
+ if ((cond_code == EQ_EXPR || cond_code == NE_EXPR)
&& TREE_CODE (op0) == SSA_NAME
&& integer_zerop (op1))
{
= simplify_control_stmt_condition_1 (e, def_stmt, avail_exprs_stack,
rhs1, NE_EXPR, op1,
dummy_cond, simplify,
- handle_dominating_asserts,
limit - 1);
if (res1 == NULL_TREE)
;
= simplify_control_stmt_condition_1 (e, def_stmt, avail_exprs_stack,
rhs2, NE_EXPR, op1,
dummy_cond, simplify,
- handle_dominating_asserts,
limit - 1);
if (res2 == NULL_TREE)
;
= simplify_control_stmt_condition_1 (e, def_stmt, avail_exprs_stack,
rhs1, new_cond, rhs2,
dummy_cond, simplify,
- handle_dominating_asserts,
limit - 1);
if (res != NULL_TREE && is_gimple_min_invariant (res))
return res;
}
}
- if (handle_dominating_asserts)
- {
- /* Now see if the operand was consumed by an ASSERT_EXPR
- which dominates E->src. If so, we want to replace the
- operand with the LHS of the ASSERT_EXPR. */
- if (TREE_CODE (op0) == SSA_NAME)
- op0 = lhs_of_dominating_assert (op0, e->src, stmt);
-
- if (TREE_CODE (op1) == SSA_NAME)
- op1 = lhs_of_dominating_assert (op1, e->src, stmt);
- }
-
gimple_cond_set_code (dummy_cond, cond_code);
gimple_cond_set_lhs (dummy_cond, op0);
gimple_cond_set_rhs (dummy_cond, op1);
then use the pass specific callback to simplify the condition. */
if (!res
|| !is_gimple_min_invariant (res))
- res = (*simplify) (dummy_cond, stmt, avail_exprs_stack);
+ res = (*simplify) (dummy_cond, stmt, avail_exprs_stack, e->src);
return res;
}
returning TRUE from the toplevel call. Otherwise do nothing and
return false.
- DUMMY_COND, HANDLE_DOMINATING_ASSERTS and SIMPLIFY are used to
- try and simplify the condition at the end of TAKEN_EDGE->dest.
+ DUMMY_COND, SIMPLIFY are used to try and simplify the condition at the
+ end of TAKEN_EDGE->dest.
The available expression table is referenced via AVAIL_EXPRS_STACK. */
thread_around_empty_blocks (edge taken_edge,
gcond *dummy_cond,
class avail_exprs_stack *avail_exprs_stack,
- bool handle_dominating_asserts,
pfn_simplify simplify,
bitmap visited,
vec<jump_thread_edge *> *path)
return thread_around_empty_blocks (taken_edge,
dummy_cond,
avail_exprs_stack,
- handle_dominating_asserts,
simplify,
visited,
path);
/* Extract and simplify the condition. */
cond = simplify_control_stmt_condition (taken_edge, stmt,
avail_exprs_stack, dummy_cond,
- simplify, handle_dominating_asserts);
+ simplify);
/* If the condition can be statically computed and we have not already
visited the destination edge, then add the taken edge to our thread
thread_around_empty_blocks (taken_edge,
dummy_cond,
avail_exprs_stack,
- handle_dominating_asserts,
simplify,
visited,
path);
DUMMY_COND is a shared cond_expr used by condition simplification as scratch,
to avoid allocating memory.
- HANDLE_DOMINATING_ASSERTS is true if we should try to replace operands of
- the simplified condition with left-hand sides of ASSERT_EXPRs they are
- used in.
-
STACK is used to undo temporary equivalences created during the walk of
E->dest.
static int
thread_through_normal_block (edge e,
gcond *dummy_cond,
- bool handle_dominating_asserts,
const_and_copies *const_and_copies,
avail_exprs_stack *avail_exprs_stack,
pfn_simplify simplify,
bitmap visited)
{
/* We want to record any equivalences created by traversing E. */
- if (!handle_dominating_asserts)
- record_temporary_equivalences (e, const_and_copies, avail_exprs_stack);
+ record_temporary_equivalences (e, const_and_copies, avail_exprs_stack);
/* PHIs create temporary equivalences.
Note that if we found a PHI that made the block non-threadable, then
/* Extract and simplify the condition. */
cond = simplify_control_stmt_condition (e, stmt, avail_exprs_stack,
- dummy_cond, simplify,
- handle_dominating_asserts);
+ dummy_cond, simplify);
if (!cond)
return 0;
thread_around_empty_blocks (taken_edge,
dummy_cond,
avail_exprs_stack,
- handle_dominating_asserts,
simplify,
visited,
path);
DUMMY_COND is a shared cond_expr used by condition simplification as scratch,
to avoid allocating memory.
- HANDLE_DOMINATING_ASSERTS is true if we should try to replace operands of
- the simplified condition with left-hand sides of ASSERT_EXPRs they are
- used in.
-
CONST_AND_COPIES is used to undo temporary equivalences created during the
walk of E->dest.
void
thread_across_edge (gcond *dummy_cond,
edge e,
- bool handle_dominating_asserts,
class const_and_copies *const_and_copies,
class avail_exprs_stack *avail_exprs_stack,
tree (*simplify) (gimple *, gimple *,
- class avail_exprs_stack *))
+ class avail_exprs_stack *, basic_block))
{
bitmap visited = BITMAP_ALLOC (NULL);
int threaded;
if ((e->flags & EDGE_DFS_BACK) == 0)
threaded = thread_through_normal_block (e, dummy_cond,
- handle_dominating_asserts,
const_and_copies,
avail_exprs_stack,
simplify, path,
found = thread_around_empty_blocks (taken_edge,
dummy_cond,
avail_exprs_stack,
- handle_dominating_asserts,
simplify,
visited,
path);
if (!found)
found = thread_through_normal_block (path->last ()->e, dummy_cond,
- handle_dominating_asserts,
const_and_copies,
avail_exprs_stack,
simplify, path,
/* Unwindable const/copy equivalences. */
const_and_copies *equiv_stack;
+/* Return the LHS of any ASSERT_EXPR where OP appears as the first
+ argument to the ASSERT_EXPR and in which the ASSERT_EXPR dominates
+ BB. If no such ASSERT_EXPR is found, return OP. */
+
+static tree
+lhs_of_dominating_assert (tree op, basic_block bb, gimple *stmt)
+{
+ imm_use_iterator imm_iter;
+ gimple *use_stmt;
+ use_operand_p use_p;
+
+ if (TREE_CODE (op) == SSA_NAME)
+ {
+ FOR_EACH_IMM_USE_FAST (use_p, imm_iter, op)
+ {
+ use_stmt = USE_STMT (use_p);
+ if (use_stmt != stmt
+ && gimple_assign_single_p (use_stmt)
+ && TREE_CODE (gimple_assign_rhs1 (use_stmt)) == ASSERT_EXPR
+ && TREE_OPERAND (gimple_assign_rhs1 (use_stmt), 0) == op
+ && dominated_by_p (CDI_DOMINATORS, bb, gimple_bb (use_stmt)))
+ return gimple_assign_lhs (use_stmt);
+ }
+ }
+ return op;
+}
+
/* A trivial wrapper so that we can present the generic jump threading
code with a simple API for simplifying statements. STMT is the
statement we want to simplify, WITHIN_STMT provides the location
static tree
simplify_stmt_for_jump_threading (gimple *stmt, gimple *within_stmt,
- class avail_exprs_stack *avail_exprs_stack ATTRIBUTE_UNUSED)
+ class avail_exprs_stack *avail_exprs_stack ATTRIBUTE_UNUSED,
+ basic_block bb)
{
if (gcond *cond_stmt = dyn_cast <gcond *> (stmt))
- return vrp_evaluate_conditional (gimple_cond_code (cond_stmt),
- gimple_cond_lhs (cond_stmt),
- gimple_cond_rhs (cond_stmt),
- within_stmt);
+ {
+ tree op0 = gimple_cond_lhs (cond_stmt);
+ op0 = lhs_of_dominating_assert (op0, bb, stmt);
+
+ tree op1 = gimple_cond_rhs (cond_stmt);
+ op1 = lhs_of_dominating_assert (op1, bb, stmt);
+
+ return vrp_evaluate_conditional (gimple_cond_code (cond_stmt),
+ op0, op1, within_stmt);
+ }
/* We simplify a switch statement by trying to determine which case label
will be taken. If we are successful then we return the corresponding
if (TREE_CODE (op) != SSA_NAME)
return NULL_TREE;
+ op = lhs_of_dominating_assert (op, bb, stmt);
+
value_range *vr = get_value_range (op);
if ((vr->type != VR_RANGE && vr->type != VR_ANTI_RANGE)
|| symbolic_range_p (vr))
if (e->flags & (EDGE_IGNORE | EDGE_COMPLEX))
continue;
- thread_across_edge (dummy, e, true, equiv_stack, NULL,
+ thread_across_edge (dummy, e, equiv_stack, NULL,
simplify_stmt_for_jump_threading);
}
}