tree-vrp.c (evrp_dom_walker::before_dom_children): Handle not visited but non-executa...
authorRichard Biener <rguenther@suse.de>
Tue, 18 Oct 2016 11:02:24 +0000 (11:02 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Tue, 18 Oct 2016 11:02:24 +0000 (11:02 +0000)
2016-10-18  Richard Biener  <rguenther@suse.de>

* tree-vrp.c (evrp_dom_walker::before_dom_children): Handle
not visited but non-executable predecessors.  Return taken edge.
Simplify conditions and refactor propagation vs. folding step.

* gcc.dg/tree-ssa/pr20318.c: Disable EVRP.
* gcc.dg/tree-ssa/pr21001.c: Likewise.
* gcc.dg/tree-ssa/pr21090.c: Likewise.
* gcc.dg/tree-ssa/pr21294.c: Likewise.
* gcc.dg/tree-ssa/pr21563.c: Likewise.
* gcc.dg/tree-ssa/pr23744.c: Likewise.
* gcc.dg/tree-ssa/pr25382.c: Likewise.
* gcc.dg/tree-ssa/pr68431.c: Likewise.
* gcc.dg/tree-ssa/vrp03.c: Likewise.
* gcc.dg/tree-ssa/vrp06.c: Likewise.
* gcc.dg/tree-ssa/vrp07.c: Likewise.
* gcc.dg/tree-ssa/vrp09.c: Likewise.
* gcc.dg/tree-ssa/vrp19.c: Likewise.
* gcc.dg/tree-ssa/vrp20.c: Likewise.
* gcc.dg/tree-ssa/vrp92.c: Likewise.
* gcc.dg/pr68217.c: Likewise.
* gcc.dg/predict-9.c: Likewise.
* gcc.dg/tree-prof/val-prof-5.c: Adjust.
* gcc.dg/predict-1.c: Likewise.

From-SVN: r241300

22 files changed:
gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr68217.c
gcc/testsuite/gcc.dg/predict-1.c
gcc/testsuite/gcc.dg/predict-9.c
gcc/testsuite/gcc.dg/tree-prof/val-prof-5.c
gcc/testsuite/gcc.dg/tree-ssa/pr20318.c
gcc/testsuite/gcc.dg/tree-ssa/pr21001.c
gcc/testsuite/gcc.dg/tree-ssa/pr21090.c
gcc/testsuite/gcc.dg/tree-ssa/pr21294.c
gcc/testsuite/gcc.dg/tree-ssa/pr21563.c
gcc/testsuite/gcc.dg/tree-ssa/pr23744.c
gcc/testsuite/gcc.dg/tree-ssa/pr25382.c
gcc/testsuite/gcc.dg/tree-ssa/pr68431.c
gcc/testsuite/gcc.dg/tree-ssa/vrp03.c
gcc/testsuite/gcc.dg/tree-ssa/vrp06.c
gcc/testsuite/gcc.dg/tree-ssa/vrp07.c
gcc/testsuite/gcc.dg/tree-ssa/vrp09.c
gcc/testsuite/gcc.dg/tree-ssa/vrp19.c
gcc/testsuite/gcc.dg/tree-ssa/vrp20.c
gcc/testsuite/gcc.dg/tree-ssa/vrp92.c
gcc/tree-vrp.c

index 9e986643c562dffd54f0810c9de2add511161f0f..80c9870e7cbd812b1c692f136ded78f72cad8d1b 100644 (file)
@@ -1,3 +1,9 @@
+2016-10-18  Richard Biener  <rguenther@suse.de>
+
+       * tree-vrp.c (evrp_dom_walker::before_dom_children): Handle
+       not visited but non-executable predecessors.  Return taken edge.
+       Simplify conditions and refactor propagation vs. folding step.
+
 2016-10-18  Segher Boessenkool  <segher@kernel.crashing.org>
 
        * config/rs6000/rs6000.c (rs6000_savres_strategy): Do not select
index 6d57099bfc51d1a5832cb61b13d999105d380169..0ad84587141a8c30b995397f387aeee4120559f0 100644 (file)
@@ -1,3 +1,25 @@
+2016-10-18  Richard Biener  <rguenther@suse.de>
+
+       * gcc.dg/tree-ssa/pr20318.c: Disable EVRP.
+       * gcc.dg/tree-ssa/pr21001.c: Likewise.
+       * gcc.dg/tree-ssa/pr21090.c: Likewise.
+       * gcc.dg/tree-ssa/pr21294.c: Likewise.
+       * gcc.dg/tree-ssa/pr21563.c: Likewise.
+       * gcc.dg/tree-ssa/pr23744.c: Likewise.
+       * gcc.dg/tree-ssa/pr25382.c: Likewise.
+       * gcc.dg/tree-ssa/pr68431.c: Likewise.
+       * gcc.dg/tree-ssa/vrp03.c: Likewise.
+       * gcc.dg/tree-ssa/vrp06.c: Likewise.
+       * gcc.dg/tree-ssa/vrp07.c: Likewise.
+       * gcc.dg/tree-ssa/vrp09.c: Likewise.
+       * gcc.dg/tree-ssa/vrp19.c: Likewise.
+       * gcc.dg/tree-ssa/vrp20.c: Likewise.
+       * gcc.dg/tree-ssa/vrp92.c: Likewise.
+       * gcc.dg/pr68217.c: Likewise.
+       * gcc.dg/predict-9.c: Likewise.
+       * gcc.dg/tree-prof/val-prof-5.c: Adjust.
+       * gcc.dg/predict-1.c: Likewise.
+
 2016-10-17  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
 
        * gfortran.dg/dtio_17.f90: New test.
index 426a99a6b61ac63888b49bc7c2d98b5410821a11..c5b0d1ff199dc1bb0962e4c28655281d5044dbd6 100644 (file)
@@ -1,6 +1,5 @@
-
 /* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-vrp1" } */
+/* { dg-options "-O2 -fdisable-tree-evrp -fdump-tree-vrp1" } */
 
 int foo (void)
 {
index 10d62bac5d5cd7ddeaa6571a5592be84f9dc9818..65f6bad9d7c9595cdd90f7a83d0601d274a28a66 100644 (file)
@@ -23,4 +23,4 @@ void foo (int bound)
     }
 }
 
-/* { dg-final { scan-tree-dump-times "guess loop iv compare heuristics of edge\[^:\]*: 2.0%" 5 "profile_estimate"} } */
+/* { dg-final { scan-tree-dump-times "guess loop iv compare heuristics of edge\[^:\]*: 2.0%" 4 "profile_estimate"} } */
index 196e31c60ee66e06b36aa8842736e177c80d6ac7..ec4675195042ea82abc95dff6081adac90f6844d 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-profile_estimate" } */
+/* { dg-options "-O2 -fdisable-tree-evrp -fdump-tree-profile_estimate" } */
 
 extern int global;
 extern int global2;
index caf97ce4f878e87a2cc1f5dc76adff9c1ca19fc6..7f4a15b778626edc244ff932c715c7a90525b198 100644 (file)
@@ -6,7 +6,7 @@ main()
 {
        int i;
        for (i = 0; i < 1000; i++)
-               if (a[i])
+               if (a[i] != 1)
                        a[i]/=b;
                else
                        a[i]/=b;
index 41f569ef001510783bf4ae270fb153e93ff1f8b8..80fd72668715909ce45f57553db5e9601ce1adf7 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile { target { ! keeps_null_pointer_checks } } } */
-/* { dg-options "-O2 -fdump-tree-original -fdump-tree-vrp1 -fdelete-null-pointer-checks" } */
+/* { dg-options "-O2 -fdump-tree-original -fdump-tree-vrp1 -fdelete-null-pointer-checks -fdisable-tree-evrp" } */
 
 extern int* f(int) __attribute__((returns_nonnull));
 extern void eliminate ();
index 482d530e9ab7b30aecfb2123977051cefc0ce7d4..719360a015f9041ef61225870beaa0271e05bfdc 100644 (file)
@@ -5,7 +5,7 @@
    range information out of the conditional.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O2 -fno-tree-dominator-opts -fno-tree-fre -fdump-tree-vrp1-details" } */
+/* { dg-options "-O2 -fno-tree-dominator-opts -fno-tree-fre -fdisable-tree-evrp -fdump-tree-vrp1-details" } */
 
 int
 foo (int a)
index 26d0d55903183dd8da77e58f6192a10c713a0478..3909adb72d43bd161f2d195688c0f57811b20210 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-vrp1 -fdelete-null-pointer-checks" } */
+/* { dg-options "-O2 -fdisable-tree-evrp -fdump-tree-vrp1 -fdelete-null-pointer-checks" } */
 
 int g, h;
 
index f694fb2caf04742072b600a0c3e3a63cb40c7d08..cc7d4cdf3381bf3d356eb9adcda8580cdb95a175 100644 (file)
@@ -4,7 +4,7 @@
    allows us to eliminate the second "if" statement.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O2 -fno-tree-dominator-opts -fdump-tree-vrp1-details" } */
+/* { dg-options "-O2 -fno-tree-dominator-opts -fdisable-tree-evrp -fdump-tree-vrp1-details" } */
 
 struct f {
   int i;
index 2cc2599700c8d5d0ad10b53394df3b6fdb2fa86f..9c67a3acb46a75ca8558a487cd8edc885d0ba2dd 100644 (file)
@@ -2,7 +2,7 @@
    Make sure VRP folds the second "if" statement.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O2 -fno-tree-dominator-opts -fdump-tree-vrp1-details" } */
+/* { dg-options "-O2 -fno-tree-dominator-opts -fdisable-tree-evrp -fdump-tree-vrp1-details" } */
 
 int
 foo (int a)
index 9d662f25c319bfe31a7cab09577f9e06e2cc81d3..3385aa1e42483cf5089b55b2f6c608ba0bfa863c 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fno-tree-ccp -fdump-tree-vrp1" } */
+/* { dg-options "-O2 -fno-tree-ccp -fdisable-tree-evrp -fdump-tree-vrp1" } */
 
 void h (void);
 
index dcf91480673164e1d29298a52dc59a3303bb2bf7..d74765551c2a137aeb4db7d3e009f2bff8d157f4 100644 (file)
@@ -3,7 +3,7 @@
    Check that VRP now gets ranges from BIT_AND_EXPRs.  */
 
 /* { dg-do compile } */
-/* { dg-options "-O2 -fno-tree-ccp -fdump-tree-vrp1" } */
+/* { dg-options "-O2 -fno-tree-ccp -fdisable-tree-evrp -fdump-tree-vrp1" } */
 
 int
 foo (int a)
index 3bd3843ed344be2f30537fca8e716dcff3c1ca5d..9c42563b67b91ca13deff4f7335fed17323f2eb5 100644 (file)
@@ -1,5 +1,5 @@
 /* PR tree-optimization/68431 */
-/* { dg-options "-O2 -fdump-tree-vrp1-details" } */
+/* { dg-options "-O2 -fdisable-tree-evrp -fdump-tree-vrp1-details" } */
 
 unsigned int x = 1;
 int
index 59146bf2b621b92ce0022dfe943eef1b5c5a48bb..bafb65a53d63e5d1f2c94a5aca7f08de60e473c6 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-vrp1" } */
+/* { dg-options "-O2 -fdisable-tree-evrp -fdump-tree-vrp1" } */
 
 struct A
 {
index c4ce1703f551a7a0d64fc14e0ce4c13f63b72f2d..a872bc4373123a8d40878dc9afbf0df40e484f20 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-vrp1" } */
+/* { dg-options "-O2 -fdisable-tree-evrp -fdump-tree-vrp1" } */
 
 int baz (void);
 
index a5bd6708d9f9bc0484131cd34f6800e07e2f8bd9..0f3f280e4e15c5ba82b8ee14e2d1bca7b9769090 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fno-tree-fre -fdump-tree-vrp1-details -fdelete-null-pointer-checks" } */
+/* { dg-options "-O2 -fno-tree-fre -fdisable-tree-evrp -fdump-tree-vrp1-details -fdelete-null-pointer-checks" } */
 
 int
 foo (int i, int *p)
index d42a566a99f21713724fcee513db4bfbd84bcbf4..56cc50c5f1d69e1b2397617bd3233d502cef7775 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fno-tree-fre -fdump-tree-vrp1 -std=gnu89" } */
+/* { dg-options "-O2 -fno-tree-fre -fdisable-tree-evrp -fdump-tree-vrp1 -std=gnu89" } */
 
 foo (int *p)
 {
index cecacb665637b783a571aa8e3df5aa22f6a887a4..40373fde163bee41af7947d2d38663bfbd45200b 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-fwrapv -O1 -ftree-vrp -fdump-tree-vrp1" } */
+/* { dg-options "-fwrapv -O1 -ftree-vrp -fdisable-tree-evrp -fdump-tree-vrp1" } */
 
 #include <limits.h>
 extern void abort ();
index 60d17313152c611876c20d68ee01b312e053ada8..4a3b0d73648a775a0b807d5f41b07e6bfe848cad 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-fwrapv -O1 -fno-tree-fre -ftree-vrp -fdump-tree-vrp1" } */
+/* { dg-options "-fwrapv -O1 -fno-tree-fre -fdisable-tree-evrp -ftree-vrp -fdump-tree-vrp1" } */
 
 extern void abort ();
 extern void exit (int);
index 5d5375073e6cb9c2c0c475847d08e356b0860951..213aa47609a359e5e618e2380a37b716376c3f5a 100644 (file)
@@ -1,5 +1,5 @@
 /* { dg-do compile } */
-/* { dg-options "-O2 -fdump-tree-vrp1-details -fdisable-tree-ethread" } */
+/* { dg-options "-O2 -fdisable-tree-evrp -fdump-tree-vrp1-details -fdisable-tree-ethread" } */
 
 void bar (void);
 int foo (int i, int j)
index 31f4f25cced9cafd48c9f0f173d03c2b2000c220..6a7adaeff83edf32b310124feaea767cab486111 100644 (file)
@@ -10747,12 +10747,13 @@ evrp_dom_walker::before_dom_children (basic_block bb)
   gimple_stmt_iterator gsi;
   edge e;
   edge_iterator ei;
-  bool has_unvisived_preds = false;
+  bool has_unvisited_preds = false;
 
   FOR_EACH_EDGE (e, ei, bb->preds)
-    if (!(e->src->flags & BB_VISITED))
+    if (e->flags & EDGE_EXECUTABLE
+       && !(e->src->flags & BB_VISITED))
       {
-       has_unvisived_preds = true;
+       has_unvisited_preds = true;
        break;
       }
 
@@ -10762,7 +10763,7 @@ evrp_dom_walker::before_dom_children (basic_block bb)
       gphi *phi = gpi.phi ();
       tree lhs = PHI_RESULT (phi);
       value_range vr_result = VR_INITIALIZER;
-      if (!has_unvisived_preds
+      if (!has_unvisited_preds
          && stmt_interesting_for_vrp (phi))
        extract_range_from_phi_node (phi, &vr_result);
       else
@@ -10770,89 +10771,98 @@ evrp_dom_walker::before_dom_children (basic_block bb)
       update_value_range (lhs, &vr_result);
     }
 
+  edge taken_edge = NULL;
+
   /* Visit all other stmts and discover any new VRs possible.  */
   for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
     {
       gimple *stmt = gsi_stmt (gsi);
-      edge taken_edge;
       tree output = NULL_TREE;
       gimple *old_stmt = stmt;
       bool was_noreturn = (is_gimple_call (stmt)
                           && gimple_call_noreturn_p (stmt));
 
-      /* TODO, if found taken_edge, we should visit (return it) and travel
-        again to improve VR as done in DOM/SCCVN optimizations.  It should
-        be done carefully as stmts might prematurely leave a BB like
-        in EH.  */
-      if (stmt_interesting_for_vrp (stmt))
+      if (gcond *cond = dyn_cast <gcond *> (stmt))
+       {
+         vrp_visit_cond_stmt (cond, &taken_edge);
+         if (taken_edge)
+           {
+             if (taken_edge->flags & EDGE_TRUE_VALUE)
+               gimple_cond_make_true (cond);
+             else if (taken_edge->flags & EDGE_FALSE_VALUE)
+               gimple_cond_make_false (cond);
+             else
+               gcc_unreachable ();
+           }
+       }
+      else if (stmt_interesting_for_vrp (stmt))
        {
+         edge taken_edge;
          value_range vr = VR_INITIALIZER;
          extract_range_from_stmt (stmt, &taken_edge, &output, &vr);
          if (output
              && (vr.type == VR_RANGE || vr.type == VR_ANTI_RANGE))
-           update_value_range (output, &vr);
-         else
-           set_defs_to_varying (stmt);
+           {
+             update_value_range (output, &vr);
+             vr = *get_value_range (output);
 
-         /* Try folding stmts with the VR discovered.  */
-         bool did_replace
-           = replace_uses_in (stmt,
-                              op_with_constant_singleton_value_range);
-         if (fold_stmt (&gsi, follow_single_use_edges)
-             || did_replace)
-           update_stmt (gsi_stmt (gsi));
 
-         if (did_replace)
-           {
-             /* If we cleaned up EH information from the statement,
-                remove EH edges.  */
-             if (maybe_clean_or_replace_eh_stmt (old_stmt, stmt))
-               bitmap_set_bit (need_eh_cleanup, bb->index);
-
-             /* If we turned a not noreturn call into a noreturn one
-                schedule it for fixup.  */
-             if (!was_noreturn
-                 && is_gimple_call (stmt)
-                 && gimple_call_noreturn_p (stmt))
-               stmts_to_fixup.safe_push (stmt);
-
-             if (gimple_assign_single_p (stmt))
+             /* Set the SSA with the value range.  */
+             if (INTEGRAL_TYPE_P (TREE_TYPE (output)))
                {
-                 tree rhs = gimple_assign_rhs1 (stmt);
-                 if (TREE_CODE (rhs) == ADDR_EXPR)
-                   recompute_tree_invariant_for_addr_expr (rhs);
+                 if ((vr.type == VR_RANGE
+                      || vr.type == VR_ANTI_RANGE)
+                     && (TREE_CODE (vr.min) == INTEGER_CST)
+                     && (TREE_CODE (vr.max) == INTEGER_CST))
+                   set_range_info (output, vr.type, vr.min, vr.max);
                }
+             else if (POINTER_TYPE_P (TREE_TYPE (output))
+                      && ((vr.type == VR_RANGE
+                           && range_includes_zero_p (vr.min,
+                                                     vr.max) == 0)
+                          || (vr.type == VR_ANTI_RANGE
+                              && range_includes_zero_p (vr.min,
+                                                        vr.max) == 1)))
+               set_ptr_nonnull (output);
            }
+         else
+           set_defs_to_varying (stmt);
+       }
+      else
+       set_defs_to_varying (stmt);
+
+      /* Try folding stmts with the VR discovered.  */
+      bool did_replace
+       = replace_uses_in (stmt, op_with_constant_singleton_value_range);
+      if (fold_stmt (&gsi, follow_single_use_edges)
+         || did_replace)
+       update_stmt (gsi_stmt (gsi));
+
+      if (did_replace)
+       {
+         /* If we cleaned up EH information from the statement,
+            remove EH edges.  */
+         if (maybe_clean_or_replace_eh_stmt (old_stmt, stmt))
+           bitmap_set_bit (need_eh_cleanup, bb->index);
 
-         def_operand_p def_p = SINGLE_SSA_DEF_OPERAND (stmt, SSA_OP_DEF);
-         /* Set the SSA with the value range.  */
-         if (def_p
-             && TREE_CODE (DEF_FROM_PTR (def_p)) == SSA_NAME)
+         /* If we turned a not noreturn call into a noreturn one
+            schedule it for fixup.  */
+         if (!was_noreturn
+             && is_gimple_call (stmt)
+             && gimple_call_noreturn_p (stmt))
+           stmts_to_fixup.safe_push (stmt);
+
+         if (gimple_assign_single_p (stmt))
            {
-             tree def = DEF_FROM_PTR (def_p);
-             value_range *vr = get_value_range (def);
-
-             if (INTEGRAL_TYPE_P (TREE_TYPE (DEF_FROM_PTR (def_p)))
-                 && (vr->type == VR_RANGE
-                     || vr->type == VR_ANTI_RANGE)
-                 && (TREE_CODE (vr->min) == INTEGER_CST)
-                 && (TREE_CODE (vr->max) == INTEGER_CST))
-               set_range_info (def, vr->type, vr->min, vr->max);
-             else if (POINTER_TYPE_P (TREE_TYPE (DEF_FROM_PTR (def_p)))
-                      && ((vr->type == VR_RANGE
-                           && range_includes_zero_p (vr->min,
-                                                     vr->max) == 0)
-                          || (vr->type == VR_ANTI_RANGE
-                              && range_includes_zero_p (vr->min,
-                                                        vr->max) == 1)))
-               set_ptr_nonnull (def);
+             tree rhs = gimple_assign_rhs1 (stmt);
+             if (TREE_CODE (rhs) == ADDR_EXPR)
+               recompute_tree_invariant_for_addr_expr (rhs);
            }
        }
-      else
-       set_defs_to_varying (stmt);
     }
   bb->flags |= BB_VISITED;
-  return NULL;
+
+  return taken_edge;
 }
 
 /* Restore/pop VRs valid only for BB when we leave BB.  */