public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-4695] Move vrp_simplify_cond_using_ranges into the simplifier.
@ 2021-10-26 0:03 Andrew Macleod
0 siblings, 0 replies; only message in thread
From: Andrew Macleod @ 2021-10-26 0:03 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:f5bacd9c5be5e129688d9c91eeed05e7b968117e
commit r12-4695-gf5bacd9c5be5e129688d9c91eeed05e7b968117e
Author: Andrew MacLeod <amacleod@redhat.com>
Date: Mon Oct 25 18:04:06 2021 -0400
Move vrp_simplify_cond_using_ranges into the simplifier.
This static VRP routine does a simplification with casted conditions. Add it
to the general simplfier, and continue to invoke if from the VRP folder.
* tree-vrp.c (vrp_simplify_cond_using_ranges): Add return type and
move to vr-values.c.
(simplify_casted_conds): Move to vrp_folder class.
(execute_vrp): Call via vrp_folder now.
* vr-values.c (simplify_cond_using_ranges_1): Call simplify_casted_cond.
(simplify_using_ranges::simplify_casted_cond): Relocate from tree-vrp.c.
* vr-values.h (simplify_casted_cond): Add prototype.
Diff:
---
gcc/tree-vrp.c | 91 ++++++++++-----------------------------------------------
gcc/vr-values.c | 69 +++++++++++++++++++++++++++++++++++++++++++
gcc/vr-values.h | 1 +
3 files changed, 85 insertions(+), 76 deletions(-)
diff --git a/gcc/tree-vrp.c b/gcc/tree-vrp.c
index a948c524098..38ea50303e0 100644
--- a/gcc/tree-vrp.c
+++ b/gcc/tree-vrp.c
@@ -4031,6 +4031,7 @@ class vrp_folder : public substitute_and_fold_engine
: substitute_and_fold_engine (/* Fold all stmts. */ true),
m_vr_values (v), simplifier (v)
{ }
+ void simplify_casted_conds (function *fun);
private:
tree value_of_expr (tree name, gimple *stmt) OVERRIDE
@@ -4117,78 +4118,6 @@ vrp_folder::fold_stmt (gimple_stmt_iterator *si)
return simplifier.simplify (si);
}
-/* STMT is a conditional at the end of a basic block.
-
- If the conditional is of the form SSA_NAME op constant and the SSA_NAME
- was set via a type conversion, try to replace the SSA_NAME with the RHS
- of the type conversion. Doing so makes the conversion dead which helps
- subsequent passes. */
-
-static void
-vrp_simplify_cond_using_ranges (range_query *query, gcond *stmt)
-{
- tree op0 = gimple_cond_lhs (stmt);
- tree op1 = gimple_cond_rhs (stmt);
-
- /* If we have a comparison of an SSA_NAME (OP0) against a constant,
- see if OP0 was set by a type conversion where the source of
- the conversion is another SSA_NAME with a range that fits
- into the range of OP0's type.
-
- If so, the conversion is redundant as the earlier SSA_NAME can be
- used for the comparison directly if we just massage the constant in the
- comparison. */
- if (TREE_CODE (op0) == SSA_NAME
- && TREE_CODE (op1) == INTEGER_CST)
- {
- gimple *def_stmt = SSA_NAME_DEF_STMT (op0);
- tree innerop;
-
- if (!is_gimple_assign (def_stmt))
- return;
-
- switch (gimple_assign_rhs_code (def_stmt))
- {
- CASE_CONVERT:
- innerop = gimple_assign_rhs1 (def_stmt);
- break;
- case VIEW_CONVERT_EXPR:
- innerop = TREE_OPERAND (gimple_assign_rhs1 (def_stmt), 0);
- if (!INTEGRAL_TYPE_P (TREE_TYPE (innerop)))
- return;
- break;
- default:
- return;
- }
-
- if (TREE_CODE (innerop) == SSA_NAME
- && !POINTER_TYPE_P (TREE_TYPE (innerop))
- && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (innerop)
- && desired_pro_or_demotion_p (TREE_TYPE (innerop), TREE_TYPE (op0)))
- {
- const value_range *vr = query->get_value_range (innerop);
-
- if (range_int_cst_p (vr)
- && range_fits_type_p (vr,
- TYPE_PRECISION (TREE_TYPE (op0)),
- TYPE_SIGN (TREE_TYPE (op0)))
- && int_fits_type_p (op1, TREE_TYPE (innerop)))
- {
- tree newconst = fold_convert (TREE_TYPE (innerop), op1);
- gimple_cond_set_lhs (stmt, innerop);
- gimple_cond_set_rhs (stmt, newconst);
- update_stmt (stmt);
- if (dump_file && (dump_flags & TDF_DETAILS))
- {
- fprintf (dump_file, "Folded into: ");
- print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
- fprintf (dump_file, "\n");
- }
- }
- }
- }
-}
-
/* A comparison of an SSA_NAME against a constant where the SSA_NAME
was set by a type conversion can often be rewritten to use the RHS
of the type conversion. Do this optimization for all conditionals
@@ -4198,15 +4127,25 @@ vrp_simplify_cond_using_ranges (range_query *query, gcond *stmt)
So that transformation is not performed until after jump threading
is complete. */
-static void
-simplify_casted_conds (function *fun, range_query *query)
+void
+vrp_folder::simplify_casted_conds (function *fun)
{
basic_block bb;
FOR_EACH_BB_FN (bb, fun)
{
gimple *last = last_stmt (bb);
if (last && gimple_code (last) == GIMPLE_COND)
- vrp_simplify_cond_using_ranges (query, as_a <gcond *> (last));
+ {
+ if (simplifier.simplify_casted_cond (as_a <gcond *> (last)))
+ {
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ {
+ fprintf (dump_file, "Folded into: ");
+ print_gimple_stmt (dump_file, last, 0, TDF_SLIM);
+ fprintf (dump_file, "\n");
+ }
+ }
+ }
}
}
@@ -4301,7 +4240,7 @@ execute_vrp (struct function *fun, bool warn_array_bounds_p)
array_checker.check ();
}
- simplify_casted_conds (fun, &vrp_vr_values);
+ folder.simplify_casted_conds (fun);
free_numbers_of_iterations_estimates (fun);
diff --git a/gcc/vr-values.c b/gcc/vr-values.c
index d0f7cb41bc8..00246c9d3af 100644
--- a/gcc/vr-values.c
+++ b/gcc/vr-values.c
@@ -3630,6 +3630,75 @@ simplify_using_ranges::simplify_cond_using_ranges_1 (gcond *stmt)
}
}
}
+ // Try to simplify casted conditions.
+ return simplify_casted_cond (stmt);
+}
+
+/* STMT is a conditional at the end of a basic block.
+
+ If the conditional is of the form SSA_NAME op constant and the SSA_NAME
+ was set via a type conversion, try to replace the SSA_NAME with the RHS
+ of the type conversion. Doing so makes the conversion dead which helps
+ subsequent passes. */
+
+bool
+simplify_using_ranges::simplify_casted_cond (gcond *stmt)
+{
+ tree op0 = gimple_cond_lhs (stmt);
+ tree op1 = gimple_cond_rhs (stmt);
+
+ /* If we have a comparison of an SSA_NAME (OP0) against a constant,
+ see if OP0 was set by a type conversion where the source of
+ the conversion is another SSA_NAME with a range that fits
+ into the range of OP0's type.
+
+ If so, the conversion is redundant as the earlier SSA_NAME can be
+ used for the comparison directly if we just massage the constant in the
+ comparison. */
+ if (TREE_CODE (op0) == SSA_NAME
+ && TREE_CODE (op1) == INTEGER_CST)
+ {
+ gimple *def_stmt = SSA_NAME_DEF_STMT (op0);
+ tree innerop;
+
+ if (!is_gimple_assign (def_stmt))
+ return false;
+
+ switch (gimple_assign_rhs_code (def_stmt))
+ {
+ CASE_CONVERT:
+ innerop = gimple_assign_rhs1 (def_stmt);
+ break;
+ case VIEW_CONVERT_EXPR:
+ innerop = TREE_OPERAND (gimple_assign_rhs1 (def_stmt), 0);
+ if (!INTEGRAL_TYPE_P (TREE_TYPE (innerop)))
+ return false;
+ break;
+ default:
+ return false;
+ }
+
+ if (TREE_CODE (innerop) == SSA_NAME
+ && !POINTER_TYPE_P (TREE_TYPE (innerop))
+ && !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (innerop)
+ && desired_pro_or_demotion_p (TREE_TYPE (innerop), TREE_TYPE (op0)))
+ {
+ const value_range *vr = query->get_value_range (innerop);
+
+ if (range_int_cst_p (vr)
+ && range_fits_type_p (vr,
+ TYPE_PRECISION (TREE_TYPE (op0)),
+ TYPE_SIGN (TREE_TYPE (op0)))
+ && int_fits_type_p (op1, TREE_TYPE (innerop)))
+ {
+ tree newconst = fold_convert (TREE_TYPE (innerop), op1);
+ gimple_cond_set_lhs (stmt, innerop);
+ gimple_cond_set_rhs (stmt, newconst);
+ update_stmt (stmt);
+ return true;
+ }
+ }
+ }
return false;
}
diff --git a/gcc/vr-values.h b/gcc/vr-values.h
index 821bcb9d58d..21dc4eaebce 100644
--- a/gcc/vr-values.h
+++ b/gcc/vr-values.h
@@ -44,6 +44,7 @@ public:
tree vrp_evaluate_conditional_warnv_with_ops (gimple *stmt, enum tree_code,
tree, tree, bool,
bool *, bool *);
+ bool simplify_casted_cond (gcond *);
private:
bool simplify_truth_ops_using_ranges (gimple_stmt_iterator *, gimple *);
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-10-26 0:03 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-26 0:03 [gcc r12-4695] Move vrp_simplify_cond_using_ranges into the simplifier Andrew Macleod
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).