Only call vrp_visit_cond_stmt if range_of_stmt doesn't resolve to a const.
authorAndrew MacLeod <amacleod@redhat.com>
Mon, 19 Jul 2021 18:02:57 +0000 (14:02 -0400)
committerAndrew MacLeod <amacleod@redhat.com>
Thu, 22 Jul 2021 12:51:59 +0000 (08:51 -0400)
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 [new file with mode: 0644]
gcc/vr-values.c

diff --git a/gcc/testsuite/gcc.dg/pr101496.c b/gcc/testsuite/gcc.dg/pr101496.c
new file mode 100644 (file)
index 0000000..091d4ad
--- /dev/null
@@ -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;
+}
+
index 1b3ec38..c999ca8 100644 (file)
@@ -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);