Hi,
This patch removes support for -funsafe-loop-optimizations, as well as 
-Wunsafe-loop-optimizations.  By its name, this option does unsafe 
optimizations by assuming all loops must terminate and doesn't wrap.  
Unfortunately, it's not as useful as expected because:
1) Simply assuming loop must terminate isn't enough.  What we really want is to 
analyze scalar evolution and loop niter bound under such assumptions.  This 
option does nothing in this aspect.
2) IIRC, this option generates bogus code for some common programs, that's why 
it's disabled by default even at Ofast level.

After I sent patches handling possible infinite loops in both (scev/niter) 
analyzer and vectorizer, it's a natural step to remove such options in GCC.  
This patch does so by deleting code for -funsafe-loop-optimizations, as well as 
-Wunsafe-loop-optimizations.  It also deletes the two now useless tests, while 
the option interface is preserved for backward compatibility purpose.

Bootstrap and test on x86_64.  Is it OK?

Thanks,
bin

2016-07-14  Bin Cheng  <bin.ch...@arm.com>

        * common.opt (funsafe-loop-optimizations): Mark ignore.
        (Wunsafe-loop-optimizations): Ditto.
        * doc/invoke.texi (funsafe-loop-optimizations): Remove.
        (Wunsafe-loop-optimizations): Ditto.
        * loop-iv.c (get_simple_loop_desc): Remove support for
        funsafe-loop-optimizations.
        * tree-ssa-loop-niter.h (number_of_iterations_exit): Remove param.
        * tree-ssa-loop-niter.c (number_of_iterations_exit): Remove param.
        (finite_loop_p): Remove support for funsafe-loop-optimizations.
        (find_loop_niter): Remove arg for number_of_iterations_exit call.
        (estimate_numbers_of_iterations_loop): Ditto.
        * ipa-inline-analysis.c (estimate_function_body_sizes): Ditto.
        * predict.c (predict_loops): Ditto.
        * tree-parloops.c (try_get_loop_niter): Ditto.
        * tree-scalar-evolution.c (number_of_latch_executions): Ditto.
        * tree-ssa-loop-ivcanon.c (remove_redundant_iv_tests): Ditto.
        * tree-ssa-loop-ivopts.c (niter_for_exit): Ditto.
        * tree-ssa-loop-manip.c (can_unroll_loop_p): Ditto.

gcc/testsuite/ChangeLog
2016-07-14  Bin Cheng  <bin.ch...@arm.com>

        * gcc.dg/tree-ssa/pr19210-1.c: Delete.
        * gcc.dg/tree-ssa/pr19210-2.c: Delete.
diff --git a/gcc/common.opt b/gcc/common.opt
index a7c5125..331e1da 100644
--- a/gcc/common.opt
+++ b/gcc/common.opt
@@ -625,8 +625,8 @@ Common Var(warn_null_dereference) Warning
 Warn if dereferencing a NULL pointer may lead to erroneous or undefined 
behavior.
 
 Wunsafe-loop-optimizations
-Common Var(warn_unsafe_loop_optimizations) Warning
-Warn if the loop cannot be optimized due to nontrivial assumptions.
+Common Ignore
+Does nothing.  Preserved for backward compatibility.
 
 Wmissing-noreturn
 Common Warning Alias(Wsuggest-attribute=noreturn)
@@ -2500,8 +2500,8 @@ Perform loop unrolling for all loops.
 ; that control loops do not overflow and that the loops with nontrivial
 ; exit condition are not infinite
 funsafe-loop-optimizations
-Common Report Var(flag_unsafe_loop_optimizations) Optimization
-Allow loop optimizations to assume that the loops behave in normal way.
+Common Ignore
+Does nothing.  Preserved for backward compatibility.
 
 fassociative-math
 Common Report Var(flag_associative_math) SetByCombined Optimization
diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi
index ca8c1b4..4241956 100644
--- a/gcc/doc/invoke.texi
+++ b/gcc/doc/invoke.texi
@@ -302,8 +302,7 @@ Objective-C and Objective-C++ Dialects}.
 -Wswitch  -Wswitch-bool  -Wswitch-default  -Wswitch-enum @gol
 -Wswitch-unreachable  -Wsync-nand @gol
 -Wsystem-headers  -Wtautological-compare  -Wtrampolines  -Wtrigraphs @gol
--Wtype-limits  -Wundef @gol
--Wuninitialized  -Wunknown-pragmas  -Wunsafe-loop-optimizations @gol
+-Wtype-limits  -Wundef -Wuninitialized  -Wunknown-pragmas @gol
 -Wunsuffixed-float-constants  -Wunused  -Wunused-function @gol
 -Wunused-label  -Wunused-local-typedefs -Wunused-parameter @gol
 -Wno-unused-result -Wunused-value @gol -Wunused-variable @gol
@@ -414,7 +413,7 @@ Objective-C and Objective-C++ Dialects}.
 -ftree-switch-conversion -ftree-tail-merge -ftree-ter @gol
 -ftree-vectorize -ftree-vrp -funconstrained-commons @gol
 -funit-at-a-time -funroll-all-loops -funroll-loops @gol
--funsafe-loop-optimizations -funsafe-math-optimizations -funswitch-loops @gol
+-funsafe-math-optimizations -funswitch-loops @gol
 -fipa-ra -fvariable-expansion-in-unroller -fvect-cost-model -fvpt @gol
 -fweb -fwhole-program -fwpa -fuse-linker-plugin @gol
 --param @var{name}=@var{value}
@@ -4986,14 +4985,6 @@ If the stack usage is (partly) dynamic and not bounded, 
it's:
 @end smallexample
 @end itemize
 
-@item -Wunsafe-loop-optimizations
-@opindex Wunsafe-loop-optimizations
-@opindex Wno-unsafe-loop-optimizations
-Warn if the loop cannot be optimized because the compiler cannot
-assume anything on the bounds of the loop indices.  With
-@option{-funsafe-loop-optimizations} warn if the compiler makes
-such assumptions.
-
 @item -Wno-pedantic-ms-format @r{(MinGW targets only)}
 @opindex Wno-pedantic-ms-format
 @opindex Wpedantic-ms-format
@@ -6817,15 +6808,6 @@ number of iterations of a loop are used to guide loop 
unrolling and peeling
 and loop exit test optimizations.
 This option is enabled by default.
 
-@item -funsafe-loop-optimizations
-@opindex funsafe-loop-optimizations
-This option tells the loop optimizer to assume that loop indices do not
-overflow, and that loops with nontrivial exit condition are not
-infinite.  This enables a wider range of loop optimizations even if
-the loop optimizer itself cannot prove that these assumptions are valid.
-If you use @option{-Wunsafe-loop-optimizations}, the compiler warns you
-if it finds this kind of loop.
-
 @item -funconstrained-commons
 @opindex funconstrained-commons
 This option tells the compiler that variables declared in common blocks
diff --git a/gcc/ipa-inline-analysis.c b/gcc/ipa-inline-analysis.c
index da29d22..6b2cf96 100644
--- a/gcc/ipa-inline-analysis.c
+++ b/gcc/ipa-inline-analysis.c
@@ -2820,7 +2820,7 @@ estimate_function_body_sizes (struct cgraph_node *node, 
bool early)
 
          exits = get_loop_exit_edges (loop);
          FOR_EACH_VEC_ELT (exits, j, ex)
-           if (number_of_iterations_exit (loop, ex, &niter_desc, false)
+           if (number_of_iterations_exit (loop, ex, &niter_desc)
                && !is_gimple_min_invariant (niter_desc.niter))
            {
              predicate will_be_nonconstant
diff --git a/gcc/loop-iv.c b/gcc/loop-iv.c
index 57fb8c1..b3d41604 100644
--- a/gcc/loop-iv.c
+++ b/gcc/loop-iv.c
@@ -3027,42 +3027,6 @@ get_simple_loop_desc (struct loop *loop)
   iv_analysis_loop_init (loop);
   find_simple_exit (loop, desc);
   loop->simple_loop_desc = desc;
-
-  if (desc->simple_p && (desc->assumptions || desc->infinite))
-    {
-      const char *wording;
-
-      /* Assume that no overflow happens and that the loop is finite.
-        We already warned at the tree level if we ran optimizations there.  */
-      if (!flag_tree_loop_optimize && warn_unsafe_loop_optimizations)
-       {
-         if (desc->infinite)
-           {
-             wording =
-               flag_unsafe_loop_optimizations
-               ? N_("assuming that the loop is not infinite")
-               : N_("cannot optimize possibly infinite loops");
-             warning (OPT_Wunsafe_loop_optimizations, "%s",
-                      gettext (wording));
-           }
-         if (desc->assumptions)
-           {
-             wording =
-               flag_unsafe_loop_optimizations
-               ? N_("assuming that the loop counter does not overflow")
-               : N_("cannot optimize loop, the loop counter may overflow");
-             warning (OPT_Wunsafe_loop_optimizations, "%s",
-                      gettext (wording));
-           }
-       }
-
-      if (flag_unsafe_loop_optimizations && single_exit (loop))
-       {
-         desc->assumptions = NULL_RTX;
-         desc->infinite = NULL_RTX;
-       }
-    }
-
   return desc;
 }
 
diff --git a/gcc/predict.c b/gcc/predict.c
index 66a88ab..373000f 100644
--- a/gcc/predict.c
+++ b/gcc/predict.c
@@ -1774,7 +1774,7 @@ predict_loops (void)
            }
          predict_extra_loop_exits (ex);
 
-         if (number_of_iterations_exit (loop, ex, &niter_desc, false, false))
+         if (number_of_iterations_exit (loop, ex, &niter_desc, false))
            niter = niter_desc.niter;
          if (!niter || TREE_CODE (niter_desc.niter) != INTEGER_CST)
            niter = loop_niter_by_eval (loop, ex);
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr19210-1.c 
b/gcc/testsuite/gcc.dg/tree-ssa/pr19210-1.c
deleted file mode 100644
index 906132c..0000000
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr19210-1.c
+++ /dev/null
@@ -1,29 +0,0 @@
-/* { dg-do compile } */
-/* { dg-options "-O2 -Wunsafe-loop-optimizations" } */
-extern void g(void);
-
-void
-f (unsigned n)
-{
-  unsigned k;
-  for(k = 0;k <= n;k++) /* { dg-warning "cannot optimize.*infinite loops" } */
-    g();
-
-  for(k = 0;k <= n;k += 4) /* { dg-warning "cannot optimize.*overflow" } */
-    g();
-
-  /* We used to get warning for this loop.  However, since then # of iterations
-     analysis improved, and we can now prove that this loop does not verflow.
-     This is because the only case when it would overflow is if n = ~0 (since
-     ~0 is divisible by 5), and this cannot be the case, since when we got
-     here, the previous loop exited, thus there exists k > n.  */
-  for(k = 5;k <= n;k += 5)
-    g();
-
-  /* So we need the following loop, instead.  */
-  for(k = 4;k <= n;k += 5) /* { dg-warning "cannot optimize.*overflow" } */
-    g();
-  
-  for(k = 15;k >= n;k--) /* { dg-warning "cannot optimize.*infinite" } */
-    g();
-}
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr19210-2.c 
b/gcc/testsuite/gcc.dg/tree-ssa/pr19210-2.c
deleted file mode 100644
index 9116e97..0000000
--- a/gcc/testsuite/gcc.dg/tree-ssa/pr19210-2.c
+++ /dev/null
@@ -1,29 +0,0 @@
-/* { dg-do compile } */
-/* { dg-options "-O2 -funsafe-loop-optimizations -Wunsafe-loop-optimizations" 
} */
-extern void g(void);
-
-void
-f (unsigned n)
-{
-  unsigned k;
-  for(k = 0;k <= n;k++) /* { dg-warning "assuming.*not infinite" } */
-    g();
-
-  for(k = 5;k <= n;k += 4) /* { dg-warning "assuming.*not overflow" } */
-    g();
-
-  /* We used to get warning for this loop.  However, since then # of iterations
-     analysis improved, and we can now prove that this loop does not verflow.
-     This is because the only case when it would overflow is if n = ~0 (since
-     ~0 is divisible by 5), and this cannot be the case, since when we got
-     here, the previous loop exited, thus there exists k > n.  */
-  for(k = 5;k <= n;k += 5)
-    g();
-
-  for(k = 4;k <= n;k += 5) /* { dg-warning "assuming.*not overflow" } */
-    g();
-
-  for(k = 15;k >= n;k--) /* { dg-warning "assuming.*not infinite" } */
-    g();
-
-}
diff --git a/gcc/tree-parloops.c b/gcc/tree-parloops.c
index 1303ffc..be4f4fa 100644
--- a/gcc/tree-parloops.c
+++ b/gcc/tree-parloops.c
@@ -2609,7 +2609,7 @@ try_get_loop_niter (loop_p loop, struct tree_niter_desc 
*niter)
   /* We need to know # of iterations, and there should be no uses of values
      defined inside loop outside of it, unless the values are invariants of
      the loop.  */
-  if (!number_of_iterations_exit (loop, exit, niter, false))
+  if (!number_of_iterations_exit (loop, exit, niter))
     {
       if (dump_file && (dump_flags & TDF_DETAILS))
        fprintf (dump_file, "  FAILED: number of iterations not known\n");
diff --git a/gcc/tree-scalar-evolution.c b/gcc/tree-scalar-evolution.c
index d8ed84a..a5c8360 100644
--- a/gcc/tree-scalar-evolution.c
+++ b/gcc/tree-scalar-evolution.c
@@ -3076,7 +3076,7 @@ number_of_latch_executions (struct loop *loop)
   res = chrec_dont_know;
   exit = single_exit (loop);
 
-  if (exit && number_of_iterations_exit (loop, exit, &niter_desc, false))
+  if (exit && number_of_iterations_exit (loop, exit, &niter_desc))
     {
       may_be_zero = niter_desc.may_be_zero;
       res = niter_desc.niter;
diff --git a/gcc/tree-ssa-loop-ivcanon.c b/gcc/tree-ssa-loop-ivcanon.c
index 76ecba4..595fc92 100644
--- a/gcc/tree-ssa-loop-ivcanon.c
+++ b/gcc/tree-ssa-loop-ivcanon.c
@@ -571,8 +571,7 @@ remove_redundant_iv_tests (struct loop *loop)
 
          /* Only when we know the actual number of iterations, not
             just a bound, we can remove the exit.  */
-         if (!number_of_iterations_exit (loop, exit_edge,
-                                         &niter, false, false)
+         if (!number_of_iterations_exit (loop, exit_edge, &niter, false)
              || !integer_onep (niter.assumptions)
              || !integer_zerop (niter.may_be_zero)
              || !niter.niter
diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c
index f5f6e78..59a78c9 100644
--- a/gcc/tree-ssa-loop-ivopts.c
+++ b/gcc/tree-ssa-loop-ivopts.c
@@ -1019,9 +1019,8 @@ niter_for_exit (struct ivopts_data *data, edge exit)
         names that appear in phi nodes on abnormal edges, so that we do not
         create overlapping life ranges for them (PR 27283).  */
       desc = XNEW (struct tree_niter_desc);
-      if (!number_of_iterations_exit (data->current_loop,
-                                     exit, desc, true)
-         || contains_abnormal_ssa_name_p (desc->niter))
+      if (!number_of_iterations_exit (data->current_loop, exit, desc)
+         || contains_abnormal_ssa_name_p (desc->niter))
        {
          XDELETE (desc);
          desc = NULL;
diff --git a/gcc/tree-ssa-loop-manip.c b/gcc/tree-ssa-loop-manip.c
index e87d290..b18686b 100644
--- a/gcc/tree-ssa-loop-manip.c
+++ b/gcc/tree-ssa-loop-manip.c
@@ -933,7 +933,7 @@ can_unroll_loop_p (struct loop *loop, unsigned factor,
   if (!exit)
     return false;
 
-  if (!number_of_iterations_exit (loop, exit, niter, false)
+  if (!number_of_iterations_exit (loop, exit, niter)
       || niter->cmp == ERROR_MARK
       /* Scalar evolutions analysis might have copy propagated
         the abnormal ssa names into these expressions, hence
diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c
index 5bc1c00..f2a436f 100644
--- a/gcc/tree-ssa-loop-niter.c
+++ b/gcc/tree-ssa-loop-niter.c
@@ -2322,7 +2322,7 @@ number_of_iterations_exit_assumptions (struct loop *loop, 
edge exit,
 bool
 number_of_iterations_exit (struct loop *loop, edge exit,
                           struct tree_niter_desc *niter,
-                          bool, bool every_iteration)
+                          bool every_iteration)
 {
   if (!number_of_iterations_exit_assumptions (loop, exit, niter,
                                              every_iteration))
@@ -2348,7 +2348,7 @@ find_loop_niter (struct loop *loop, edge *exit)
   *exit = NULL;
   FOR_EACH_VEC_ELT (exits, i, ex)
     {
-      if (!number_of_iterations_exit (loop, ex, &desc, false))
+      if (!number_of_iterations_exit (loop, ex, &desc))
        continue;
 
       if (integer_nonzerop (desc.may_be_zero))
@@ -2404,8 +2404,6 @@ finite_loop_p (struct loop *loop)
   widest_int nit;
   int flags;
 
-  if (flag_unsafe_loop_optimizations)
-    return true;
   flags = flags_from_decl_or_type (current_function_decl);
   if ((flags & (ECF_CONST|ECF_PURE)) && !(flags & ECF_LOOPING_CONST_OR_PURE))
     {
@@ -3751,7 +3749,7 @@ estimate_numbers_of_iterations_loop (struct loop *loop)
   likely_exit = single_likely_exit (loop);
   FOR_EACH_VEC_ELT (exits, i, ex)
     {
-      if (!number_of_iterations_exit (loop, ex, &niter_desc, false, false))
+      if (!number_of_iterations_exit (loop, ex, &niter_desc, false))
        continue;
 
       niter = niter_desc.niter;
diff --git a/gcc/tree-ssa-loop-niter.h b/gcc/tree-ssa-loop-niter.h
index 1aea580..dd672bd 100644
--- a/gcc/tree-ssa-loop-niter.h
+++ b/gcc/tree-ssa-loop-niter.h
@@ -25,7 +25,7 @@ extern tree simplify_using_initial_conditions (struct loop *,
                                               tree, tree = NULL);
 extern bool loop_only_exit_p (const struct loop *, const_edge);
 extern bool number_of_iterations_exit (struct loop *, edge,
-                                      struct tree_niter_desc *niter, bool,
+                                      struct tree_niter_desc *niter,
                                       bool every_iteration = true);
 extern bool number_of_iterations_exit_assumptions (struct loop *, edge,
                                                   struct tree_niter_desc *,

Reply via email to