aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Pinski <quic_apinski@quicinc.com>2024-04-27 18:54:45 -0700
committerAndrew Pinski <quic_apinski@quicinc.com>2024-04-30 09:11:55 -0700
commit611815e0233302e1fcccca113e6f865fa450b7ae (patch)
tree02261598447e1f7f5e2b850d366499b044f98dc7
parent9c18bdb07e299b25e7526fea16659c7ff8f0d14e (diff)
downloadgcc-611815e0233302e1fcccca113e6f865fa450b7ae.zip
gcc-611815e0233302e1fcccca113e6f865fa450b7ae.tar.gz
gcc-611815e0233302e1fcccca113e6f865fa450b7ae.tar.bz2
PHI-OPT: speed up value_replacement slightly
This adds a few early outs to value_replacement that I noticed while rewriting this to use match-and-simplify but could be committed seperately. * virtual operands won't change so return early for them * special case `A ? B : B` as that is already just `B` Also moves the check for NE/EQ earlier as calculating empty_or_with_defined_p is an IR walk for a BB and that might be big. Bootstrapped and tested on x86_64-linux-gnu with no regressions. gcc/ChangeLog: * tree-ssa-phiopt.cc (value_replacement): Move check for NE/EQ earlier. Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
-rw-r--r--gcc/tree-ssa-phiopt.cc22
1 files changed, 15 insertions, 7 deletions
diff --git a/gcc/tree-ssa-phiopt.cc b/gcc/tree-ssa-phiopt.cc
index f1e0750..a2bdcb5 100644
--- a/gcc/tree-ssa-phiopt.cc
+++ b/gcc/tree-ssa-phiopt.cc
@@ -1131,6 +1131,21 @@ value_replacement (basic_block cond_bb, basic_block middle_bb,
enum tree_code code;
bool empty_or_with_defined_p = true;
+ /* Virtual operands don't need to be handled. */
+ if (virtual_operand_p (arg1))
+ return 0;
+
+ /* Special case A ? B : B as this will always simplify to B. */
+ if (operand_equal_for_phi_arg_p (arg0, arg1))
+ return 0;
+
+ gcond *cond = as_a <gcond *> (*gsi_last_bb (cond_bb));
+ code = gimple_cond_code (cond);
+
+ /* This transformation is only valid for equality comparisons. */
+ if (code != NE_EXPR && code != EQ_EXPR)
+ return 0;
+
/* If the type says honor signed zeros we cannot do this
optimization. */
if (HONOR_SIGNED_ZEROS (arg1))
@@ -1161,13 +1176,6 @@ value_replacement (basic_block cond_bb, basic_block middle_bb,
empty_or_with_defined_p = false;
}
- gcond *cond = as_a <gcond *> (*gsi_last_bb (cond_bb));
- code = gimple_cond_code (cond);
-
- /* This transformation is only valid for equality comparisons. */
- if (code != NE_EXPR && code != EQ_EXPR)
- return 0;
-
/* We need to know which is the true edge and which is the false
edge so that we know if have abs or negative abs. */
extract_true_false_edges_from_block (cond_bb, &true_edge, &false_edge);