[gcc(refs/users/marxin/heads/if-to-switch-v5)] Simplify it rapidly!
Martin Liska
marxin@gcc.gnu.org
Tue Oct 13 13:50:53 GMT 2020
https://gcc.gnu.org/g:2a524fe657c0c0f3888c3e93f325fdfa83ac4b1c
commit 2a524fe657c0c0f3888c3e93f325fdfa83ac4b1c
Author: Martin Liska <mliska@suse.cz>
Date: Mon Oct 12 15:52:57 2020 +0200
Simplify it rapidly!
Diff:
---
gcc/gimple-if-to-switch.cc | 92 ++++++++--------------------------------------
gcc/tree-ssa-reassoc.c | 14 +++----
gcc/tree-ssa-reassoc.h | 10 +----
3 files changed, 23 insertions(+), 93 deletions(-)
diff --git a/gcc/gimple-if-to-switch.cc b/gcc/gimple-if-to-switch.cc
index ebab53f1fd0..1870a90275d 100644
--- a/gcc/gimple-if-to-switch.cc
+++ b/gcc/gimple-if-to-switch.cc
@@ -60,7 +60,7 @@ using namespace tree_switch_conversion;
struct condition_info
{
condition_info (gcond *cond): m_cond (cond), m_bb (gimple_bb (cond)),
- m_ranges (), m_true_edge(NULL), m_false_edge (NULL), m_hoisting (false)
+ m_ranges (), m_true_edge(NULL), m_false_edge (NULL)
{
m_ranges.create (0);
}
@@ -70,7 +70,6 @@ struct condition_info
vec<range_entry> m_ranges;
edge m_true_edge;
edge m_false_edge;
- bool m_hoisting;
};
@@ -371,25 +370,7 @@ convert_if_conditions_to_switch (vec<condition_info *> &chain)
remove_edge (first_cond->m_false_edge);
}
else
- {
- /* Move all statements from the BB to the BB with gswitch. */
- auto_vec<gimple *> stmts;
- for (gimple_stmt_iterator gsi = gsi_start_bb (info->m_bb);
- !gsi_end_p (gsi); gsi_next (&gsi))
- {
- gimple *stmt = gsi_stmt (gsi);
- if (gimple_code (stmt) != GIMPLE_COND)
- stmts.safe_push (stmt);
- }
-
- for (unsigned i = 0; i < stmts.length (); i++)
- {
- gimple_stmt_iterator gsi_from = gsi_for_stmt (stmts[i]);
- gsi_move_before (&gsi_from, &gsi);
- }
-
- delete_basic_block (info->m_bb);
- }
+ delete_basic_block (info->m_bb);
make_edge (first_cond->m_bb, case_bb, 0);
}
@@ -449,57 +430,33 @@ find_conditions (basic_block bb,
if (cond == NULL)
return;
- if (!bb_no_side_effects_p (bb))
+ if (!no_side_effect_bb (bb))
return;
tree lhs = gimple_cond_lhs (cond);
+ tree rhs = gimple_cond_rhs (cond);
tree_code code = gimple_cond_code (cond);
condition_info info (cond);
- if (code == NE_EXPR)
+ gassign *def;
+ if (code == NE_EXPR
+ && TREE_CODE (lhs) == SSA_NAME
+ && (def = dyn_cast<gassign *> (SSA_NAME_DEF_STMT (lhs))) != NULL
+ && integer_zerop (rhs))
{
- gassign *def;
- if (TREE_CODE (lhs) == SSA_NAME
- && (def = dyn_cast<gassign *> (SSA_NAME_DEF_STMT (lhs))) != NULL)
- {
- enum tree_code rhs_code = gimple_assign_rhs_code (def);
- if (associative_tree_code (rhs_code))
- {
- auto_vec<operand_entry *> ops;
- if (TREE_CODE (lhs) == SSA_NAME && has_zero_uses (lhs))
- ;
- else
- {
- linearize_expr_tree (&ops, def, true, true);
- unsigned length = ops.length ();
- info.m_ranges.safe_grow (length, true);
- for (unsigned i = 0; i < length; i++)
- {
- operand_entry *oe = ops[i];
- if (oe->stmt_to_insert)
- debug_gimple_stmt(oe->stmt_to_insert);
- info.m_ranges[i].idx = i;
- init_range_entry (&info.m_ranges[i], oe->op,
- oe->op
- ? NULL
- : last_stmt (BASIC_BLOCK_FOR_FN (cfun, oe->id)));
- }
- }
- }
- }
- else
+ enum tree_code rhs_code = gimple_assign_rhs_code (def);
+ if (rhs_code == BIT_IOR_EXPR)
{
- info.m_ranges.safe_grow (1, true);
- init_range_entry (&info.m_ranges[0], NULL_TREE, cond);
- gimple_set_visited (cond, true);
+ info.m_ranges.safe_grow (2, true);
+ init_range_entry (&info.m_ranges[0], gimple_assign_rhs1 (def), NULL);
+ init_range_entry (&info.m_ranges[1], gimple_assign_rhs2 (def), NULL);
}
}
- else if (code == EQ_EXPR || code == LE_EXPR)
+ else
{
info.m_ranges.safe_grow (1, true);
init_range_entry (&info.m_ranges[0], NULL_TREE, cond);
- gimple_set_visited (cond, true);
}
/* All identified ranges must have equal expression and IN_P flag. */
@@ -517,15 +474,6 @@ find_conditions (basic_block bb,
if (info.m_ranges[i].exp != expr || info.m_ranges[i].in_p != in_p)
return;
- /* Identify if the condition will need a code hoisting. */
- for (gimple_stmt_iterator gsi = gsi_start_nondebug_bb (bb);
- !gsi_end_p (gsi); gsi_next_nondebug (&gsi))
- if (!gsi_stmt (gsi)->visited)
- {
- info.m_hoisting = true;
- break;
- }
-
conditions_in_bbs->put (bb, info);
}
@@ -567,9 +515,7 @@ public:
unsigned int
pass_if_to_switch::execute (function *fun)
{
- operand_rank = new hash_map<tree, long>;
hash_map<basic_block, condition_info> conditions_in_bbs;
- bb_rank = XCNEWVEC (long, last_basic_block_for_fn (cfun));
basic_block bb;
FOR_EACH_BB_FN (bb, fun)
@@ -623,7 +569,6 @@ pass_if_to_switch::execute (function *fun)
chain.reverse ();
for (unsigned i = 0; i < chain.length (); i++)
{
- fprintf (stderr, "BB hoisting: %d\n", chain[i]->m_hoisting);
debug_bb (chain[i]->m_true_edge->src);
}
@@ -637,13 +582,6 @@ pass_if_to_switch::execute (function *fun)
}
free (rpo);
-
- delete operand_rank;
- operand_rank = NULL;
-
- free (bb_rank);
- bb_rank = NULL;
-
free_dominance_info (CDI_DOMINATORS);
return 0;
diff --git a/gcc/tree-ssa-reassoc.c b/gcc/tree-ssa-reassoc.c
index 20618f486da..96765bdd3f2 100644
--- a/gcc/tree-ssa-reassoc.c
+++ b/gcc/tree-ssa-reassoc.c
@@ -200,10 +200,10 @@ static unsigned int next_operand_entry_id;
/* Starting rank number for a given basic block, so that we can rank
operations using unmovable instructions in that BB based on the bb
depth. */
-long *bb_rank;
+static long *bb_rank;
/* Operand->rank hashtable. */
-hash_map<tree, long> *operand_rank;
+static hash_map<tree, long> *operand_rank;
/* Vector of SSA_NAMEs on which after reassociate_bb is done with
all basic blocks the CFG should be adjusted - basic blocks
@@ -1052,6 +1052,8 @@ eliminate_using_constants (enum tree_code opcode,
}
+static void linearize_expr_tree (vec<operand_entry *> *, gimple *,
+ bool, bool);
/* Structure for tracking and counting operands. */
struct oecount {
@@ -3784,9 +3786,7 @@ optimize_range_tests (enum tree_code opcode,
if (opcode == BIT_IOR_EXPR
|| (opcode == ERROR_MARK && oe->rank == BIT_IOR_EXPR))
ranges[i].in_p = !ranges[i].in_p;
-// debug_range_entry (&ranges[i]);
}
-// fprintf (stderr, "\n");
qsort (ranges, length, sizeof (*ranges), range_entry_cmp);
for (i = 0; i < length; i++)
@@ -4265,7 +4265,7 @@ suitable_cond_bb (basic_block bb, basic_block test_bb, basic_block *other_bb,
range test optimization, all SSA_NAMEs set in the bb are consumed
in the bb and there are no PHIs. */
-static bool
+bool
no_side_effect_bb (basic_block bb)
{
gimple_stmt_iterator gsi;
@@ -4674,7 +4674,7 @@ maybe_optimize_range_tests (gimple *stmt)
if (bb == first_bb)
break;
}
-// if (ops.length () > 1)
+ if (ops.length () > 1)
any_changes = optimize_range_tests (ERROR_MARK, &ops, first_bb);
if (any_changes)
{
@@ -5586,7 +5586,7 @@ try_special_add_to_ops (vec<operand_entry *> *ops,
/* Recursively linearize a binary expression that is the RHS of STMT.
Place the operands of the expression tree in the vector named OPS. */
-void
+static void
linearize_expr_tree (vec<operand_entry *> *ops, gimple *stmt,
bool is_associative, bool set_visited)
{
diff --git a/gcc/tree-ssa-reassoc.h b/gcc/tree-ssa-reassoc.h
index 8225737b334..dc7f59f1eca 100644
--- a/gcc/tree-ssa-reassoc.h
+++ b/gcc/tree-ssa-reassoc.h
@@ -40,17 +40,9 @@ struct range_entry
unsigned int idx, next;
};
-/* Starting rank number for a given basic block, so that we can rank
- operations using unmovable instructions in that BB based on the bb
- depth. */
-extern long *bb_rank;
-
-/* Operand->rank hashtable. */
-extern hash_map<tree, long> *operand_rank;
-
-void linearize_expr_tree (vec<operand_entry *> *, gimple *, bool, bool);
void dump_range_entry (FILE *file, struct range_entry *r);
void debug_range_entry (struct range_entry *r);
void init_range_entry (struct range_entry *r, tree exp, gimple *stmt);
+bool no_side_effect_bb (basic_block bb);
#endif /* GCC_SSA_REASSOC_H */
More information about the Gcc-cvs
mailing list