From e58093276a6e319c2a6d9f02e343fbf8400dab60 Mon Sep 17 00:00:00 2001
From: Andrew MacLeod <amacleod@redhat.com>
Date: Mon, 19 Jul 2021 14:02:57 -0400
Subject: [PATCH 1/3] Only call vrp_visit_cond_stmt if range_of_stmt doesn't
resolve to a const.
Eevntually all functionality will be subsumed. Until then, call it only
if needed.
gcc/
PR tree-optimization/101496
* vr-values.c (simplify_using_ranges::fold_cond): Call range_of_stmt
first, then vrp_visit_cond_Stmt.
gcc/testsuite
* gcc.dg/pr101496.c: New.
---
gcc/testsuite/gcc.dg/pr101496.c | 22 ++++++++++++++++++++++
gcc/vr-values.c | 30 +++++++++++++++++-------------
2 files changed, 39 insertions(+), 13 deletions(-)
create mode 100644 gcc/testsuite/gcc.dg/pr101496.c
new file mode 100644
@@ -0,0 +1,22 @@
+/* PR tree-optimization/101496 */
+/* { dg-do compile } */
+/* { dg-options "-O2 " } */
+
+int c_1, li_2, us_3, func_14_s_5;
+
+void func_14() {
+ {
+ unsigned uli_8 = 0;
+ lbl1806324B:
+ if (uli_8 /= us_3 |= func_14_s_5 < 0 | func_14_s_5 != c_1) {
+ uli_8 += c_1 >= us_3;
+ if (uli_8)
+ ;
+ else
+ li_2 &&func_14_s_5 <= c_1 ?: 0;
+ unsigned *ptr_9 = &uli_8;
+ }
+ }
+ goto lbl1806324B;
+}
+
@@ -3460,11 +3460,6 @@ range_fits_type_p (const value_range *vr,
bool
simplify_using_ranges::fold_cond (gcond *cond)
{
- /* ?? vrp_folder::fold_predicate_in() is a superset of this. At
- some point we should merge all variants of this code. */
- edge taken_edge;
- vrp_visit_cond_stmt (cond, &taken_edge);
-
int_range_max r;
if (query->range_of_stmt (r, cond) && r.singleton_p ())
{
@@ -3475,17 +3470,13 @@ simplify_using_ranges::fold_cond (gcond *cond)
if (r.zero_p ())
{
- gcc_checking_assert (!taken_edge
- || taken_edge->flags & EDGE_FALSE_VALUE);
- if (dump_file && (dump_flags & TDF_DETAILS) && !taken_edge)
+ if (dump_file && (dump_flags & TDF_DETAILS))
fprintf (dump_file, "\nPredicate evaluates to: 0\n");
gimple_cond_make_false (cond);
}
else
{
- gcc_checking_assert (!taken_edge
- || taken_edge->flags & EDGE_TRUE_VALUE);
- if (dump_file && (dump_flags & TDF_DETAILS) && !taken_edge)
+ if (dump_file && (dump_flags & TDF_DETAILS))
fprintf (dump_file, "\nPredicate evaluates to: 1\n");
gimple_cond_make_true (cond);
}
@@ -3493,12 +3484,25 @@ simplify_using_ranges::fold_cond (gcond *cond)
return true;
}
+ /* ?? vrp_folder::fold_predicate_in() is a superset of this. At
+ some point we should merge all variants of this code. */
+ edge taken_edge;
+ vrp_visit_cond_stmt (cond, &taken_edge);
+
if (taken_edge)
{
if (taken_edge->flags & EDGE_TRUE_VALUE)
- gimple_cond_make_true (cond);
+ {
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ fprintf (dump_file, "\nVRP Predicate evaluates to: 1\n");
+ gimple_cond_make_true (cond);
+ }
else if (taken_edge->flags & EDGE_FALSE_VALUE)
- gimple_cond_make_false (cond);
+ {
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ fprintf (dump_file, "\nVRP Predicate evaluates to: 0\n");
+ gimple_cond_make_false (cond);
+ }
else
gcc_unreachable ();
update_stmt (cond);
--
2.17.2