diff options
author | Andrew Pinski <quic_apinski@quicinc.com> | 2024-07-25 16:17:15 -0700 |
---|---|---|
committer | Thomas Koenig <tkoenig@gcc.gnu.org> | 2024-07-28 19:06:00 +0200 |
commit | 9e74470d64f3fb4086b7f29303b74ae23c39abb8 (patch) | |
tree | 7b614575a687d18f4330c9d3c82733c6e26e0c7f | |
parent | 2477f7c005a0ab42dc76d827fc55776d4f62e654 (diff) | |
download | gcc-9e74470d64f3fb4086b7f29303b74ae23c39abb8.zip gcc-9e74470d64f3fb4086b7f29303b74ae23c39abb8.tar.gz gcc-9e74470d64f3fb4086b7f29303b74ae23c39abb8.tar.bz2 |
isel: Move duplicate comparisons to its own function
This is just a small cleanup to isel and no functional changes just.
The loop inside pass_gimple_isel::execute looked was getting too
deap so let's fix that by moving it to its own function.
Bootstrapped and tested on x86_64-linux-gnu with no regressions.
gcc/ChangeLog:
* gimple-isel.cc (pass_gimple_isel::execute): Factor out
duplicate comparisons out to ...
(duplicate_comparison): New function.
Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
-rw-r--r-- | gcc/gimple-isel.cc | 66 |
1 files changed, 35 insertions, 31 deletions
diff --git a/gcc/gimple-isel.cc b/gcc/gimple-isel.cc index 57f7281..327a78e 100644 --- a/gcc/gimple-isel.cc +++ b/gcc/gimple-isel.cc @@ -395,6 +395,40 @@ gimple_expand_vec_cond_expr (struct function *fun, gimple_stmt_iterator *gsi, 5, op0a, op0b, op1, op2, tcode_tree); } +/* Duplicate COND_EXPR condition defs of STMT located in BB when they are + comparisons so RTL expansion with the help of TER + can perform better if conversion. */ +static void +duplicate_comparison (gassign *stmt, basic_block bb) +{ + imm_use_iterator imm_iter; + use_operand_p use_p; + auto_vec<gassign *, 4> cond_exprs; + unsigned cnt = 0; + tree lhs = gimple_assign_lhs (stmt); + FOR_EACH_IMM_USE_FAST (use_p, imm_iter, lhs) + { + if (is_gimple_debug (USE_STMT (use_p))) + continue; + cnt++; + if (gimple_bb (USE_STMT (use_p)) == bb + && is_gimple_assign (USE_STMT (use_p)) + && gimple_assign_rhs1_ptr (USE_STMT (use_p)) == use_p->use + && gimple_assign_rhs_code (USE_STMT (use_p)) == COND_EXPR) + cond_exprs.safe_push (as_a <gassign *> (USE_STMT (use_p))); + } + for (unsigned i = cond_exprs.length () == cnt ? 1 : 0; + i < cond_exprs.length (); ++i) + { + gassign *copy = as_a <gassign *> (gimple_copy (stmt)); + tree new_def = duplicate_ssa_name (lhs, copy); + gimple_assign_set_lhs (copy, new_def); + auto gsi2 = gsi_for_stmt (cond_exprs[i]); + gsi_insert_before (&gsi2, copy, GSI_SAME_STMT); + gimple_assign_set_rhs1 (cond_exprs[i], new_def); + update_stmt (cond_exprs[i]); + } +} namespace { @@ -469,37 +503,7 @@ pass_gimple_isel::execute (struct function *fun) tree lhs = gimple_assign_lhs (stmt); if (TREE_CODE_CLASS (code) == tcc_comparison && !has_single_use (lhs)) - { - /* Duplicate COND_EXPR condition defs when they are - comparisons so RTL expansion with the help of TER - can perform better if conversion. */ - imm_use_iterator imm_iter; - use_operand_p use_p; - auto_vec<gassign *, 4> cond_exprs; - unsigned cnt = 0; - FOR_EACH_IMM_USE_FAST (use_p, imm_iter, lhs) - { - if (is_gimple_debug (USE_STMT (use_p))) - continue; - cnt++; - if (gimple_bb (USE_STMT (use_p)) == bb - && is_gimple_assign (USE_STMT (use_p)) - && gimple_assign_rhs1_ptr (USE_STMT (use_p)) == use_p->use - && gimple_assign_rhs_code (USE_STMT (use_p)) == COND_EXPR) - cond_exprs.safe_push (as_a <gassign *> (USE_STMT (use_p))); - } - for (unsigned i = cond_exprs.length () == cnt ? 1 : 0; - i < cond_exprs.length (); ++i) - { - gassign *copy = as_a <gassign *> (gimple_copy (stmt)); - tree new_def = duplicate_ssa_name (lhs, copy); - gimple_assign_set_lhs (copy, new_def); - auto gsi2 = gsi_for_stmt (cond_exprs[i]); - gsi_insert_before (&gsi2, copy, GSI_SAME_STMT); - gimple_assign_set_rhs1 (cond_exprs[i], new_def); - update_stmt (cond_exprs[i]); - } - } + duplicate_comparison (stmt, bb); } } |