Several callers of gimple_get_lhs deal with statements that might
be phis. This patch makes gimple_get_lhs handle that case too,
so that the callers don't have to.
2018-08-28 Richard Sandiford
gcc/
* gimple.c (gimple_get_lhs): Handle gphis.
* tree-ssa-phionlycprop.c (get_lhs_or_phi_result): Delete and...
(propagate_rhs_into_lhs, eliminate_const_or_copy): ...use
gimple_get_lhs instead.
* tree-ssa-dom.c (eliminate_redundant_computations): Don't handle
phis specially before calling gimple_get_lhs.
* tree-ssa-scopedtables.c (avail_exprs_stack::lookup_avail_expr):
Likewise.
* tree-vect-loop.c (vectorizable_live_operation): Likewise.
* tree-vect-slp.c (vect_get_slp_vect_defs): Likewise.
(vect_get_slp_defs): Likewise.
* tree-vect-stmts.c (vect_get_vec_def_for_operand_1): Likewise.
(vect_get_vec_def_for_stmt_copy, vect_transform_stmt): Likewise.
Index: gcc/gimple.c
===
--- gcc/gimple.c2018-08-28 11:25:46.162880564 +0100
+++ gcc/gimple.c2018-08-28 12:05:06.203027323 +0100
@@ -1757,12 +1757,12 @@ gimple_assign_set_rhs_with_ops (gimple_s
tree
gimple_get_lhs (const gimple *stmt)
{
- enum gimple_code code = gimple_code (stmt);
-
- if (code == GIMPLE_ASSIGN)
-return gimple_assign_lhs (stmt);
- else if (code == GIMPLE_CALL)
-return gimple_call_lhs (stmt);
+ if (const gphi *phi = dyn_cast (stmt))
+return gimple_phi_result (phi);
+ else if (const gassign *assign = dyn_cast (stmt))
+return gimple_assign_lhs (assign);
+ else if (const gcall *call = dyn_cast (stmt))
+return gimple_call_lhs (call);
else
return NULL_TREE;
}
Index: gcc/tree-ssa-phionlycprop.c
===
--- gcc/tree-ssa-phionlycprop.c 2018-05-02 08:38:14.413364283 +0100
+++ gcc/tree-ssa-phionlycprop.c 2018-08-28 12:05:06.203027323 +0100
@@ -72,20 +72,6 @@ get_rhs_or_phi_arg (gimple *stmt)
}
-/* Given a statement STMT, which is either a PHI node or an assignment,
- return the "lhs" of the node. */
-
-static tree
-get_lhs_or_phi_result (gimple *stmt)
-{
- if (gimple_code (stmt) == GIMPLE_PHI)
-return gimple_phi_result (stmt);
- else if (is_gimple_assign (stmt))
-return gimple_assign_lhs (stmt);
- else
-gcc_unreachable ();
-}
-
/* Propagate RHS into all uses of LHS (when possible).
RHS and LHS are derived from STMT, which is passed in solely so
@@ -186,7 +172,7 @@ propagate_rhs_into_lhs (gimple *stmt, tr
print_gimple_stmt (dump_file, use_stmt, 0, dump_flags);
}
- result = get_lhs_or_phi_result (use_stmt);
+ result = gimple_get_lhs (use_stmt);
bitmap_set_bit (interesting_names, SSA_NAME_VERSION (result));
continue;
}
@@ -240,7 +226,7 @@ propagate_rhs_into_lhs (gimple *stmt, tr
&& (TREE_CODE (gimple_assign_rhs1 (use_stmt)) == SSA_NAME
|| is_gimple_min_invariant (gimple_assign_rhs1 (use_stmt
{
- tree result = get_lhs_or_phi_result (use_stmt);
+ tree result = gimple_get_lhs (use_stmt);
bitmap_set_bit (interesting_names, SSA_NAME_VERSION (result));
}
@@ -345,7 +331,7 @@ propagate_rhs_into_lhs (gimple *stmt, tr
eliminate_const_or_copy (gimple *stmt, bitmap interesting_names,
bitmap need_eh_cleanup)
{
- tree lhs = get_lhs_or_phi_result (stmt);
+ tree lhs = gimple_get_lhs (stmt);
tree rhs;
int version = SSA_NAME_VERSION (lhs);
bool cfg_altered = false;
Index: gcc/tree-ssa-dom.c
===
--- gcc/tree-ssa-dom.c 2018-08-28 11:25:45.842883317 +0100
+++ gcc/tree-ssa-dom.c 2018-08-28 12:05:06.203027323 +0100
@@ -1491,10 +1491,7 @@ eliminate_redundant_computations (gimple
gimple *stmt = gsi_stmt (*gsi);
- if (gimple_code (stmt) == GIMPLE_PHI)
-def = gimple_phi_result (stmt);
- else
-def = gimple_get_lhs (stmt);
+ def = gimple_get_lhs (stmt);
/* Certain expressions on the RHS can be optimized away, but can not
themselves be entered into the hash tables. */
Index: gcc/tree-ssa-scopedtables.c
===
--- gcc/tree-ssa-scopedtables.c 2018-06-14 12:27:39.536036781 +0100
+++ gcc/tree-ssa-scopedtables.c 2018-08-28 12:05:06.203027323 +0100
@@ -236,11 +236,7 @@ avail_exprs_stack::lookup_avail_expr (gi
expr_hash_elt **slot;
tree lhs;
- /* Get LHS of phi, assignment, or call; else NULL_TREE. */
- if (gimple_code (stmt) == GIMPLE_PHI)
-lhs = gimple_phi_result (stmt);
- else
-lhs = gimple_get_lhs (stmt);
+ lhs = gimple_get_lhs (stmt);
class expr_hash_elt element (stmt, lhs);
Index: gcc/tree-vect-loop.c
==