diff options
author | Andrew Pinski <quic_apinski@quicinc.com> | 2024-11-30 13:12:13 -0800 |
---|---|---|
committer | Andrew Pinski <quic_apinski@quicinc.com> | 2024-11-30 23:34:31 -0800 |
commit | 24949e640307f91a831e0fb699fea85fb9276a09 (patch) | |
tree | 5d9a4efc8f2acc3182776b5066e66f69c8f08127 /gcc | |
parent | e0ffe6620cc29154ef84dbc2ecc44d6d98a2e5c5 (diff) | |
download | gcc-24949e640307f91a831e0fb699fea85fb9276a09.zip gcc-24949e640307f91a831e0fb699fea85fb9276a09.tar.gz gcc-24949e640307f91a831e0fb699fea85fb9276a09.tar.bz2 |
gimple-lim: Reuse boolean var when moving PHI
While looking into PR 117859, I noticed that LIM
sometimes would produce `bool_var2 = bool_var1 != 0` instead
of just using bool_var2. This patch allows LIM to reuse bool_var1
in the place where bool_var2 was going to be used.
Bootstrapped and tested on x86_64-linux-gnu.
gcc/ChangeLog:
* tree-ssa-loop-im.cc (move_computations_worker): While moving
phi, reuse the lhs of the conditional if it is a boolean type.
Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/tree-ssa-loop-im.cc | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/gcc/tree-ssa-loop-im.cc b/gcc/tree-ssa-loop-im.cc index 538a058..0130a80 100644 --- a/gcc/tree-ssa-loop-im.cc +++ b/gcc/tree-ssa-loop-im.cc @@ -1304,11 +1304,22 @@ move_computations_worker (basic_block bb) edges of COND. */ extract_true_false_args_from_phi (dom, stmt, &arg0, &arg1); gcc_assert (arg0 && arg1); - t = make_ssa_name (boolean_type_node); - new_stmt = gimple_build_assign (t, gimple_cond_code (cond), - gimple_cond_lhs (cond), - gimple_cond_rhs (cond)); - gsi_insert_on_edge (loop_preheader_edge (level), new_stmt); + /* For `bool_val != 0`, reuse bool_val. */ + if (gimple_cond_code (cond) == NE_EXPR + && integer_zerop (gimple_cond_rhs (cond)) + && types_compatible_p (TREE_TYPE (gimple_cond_lhs (cond)), + boolean_type_node)) + { + t = gimple_cond_lhs (cond); + } + else + { + t = make_ssa_name (boolean_type_node); + new_stmt = gimple_build_assign (t, gimple_cond_code (cond), + gimple_cond_lhs (cond), + gimple_cond_rhs (cond)); + gsi_insert_on_edge (loop_preheader_edge (level), new_stmt); + } new_stmt = gimple_build_assign (gimple_phi_result (stmt), COND_EXPR, t, arg0, arg1); todo |= TODO_cleanup_cfg; |