Simplify loop size when step=1
authorMarc Glisse <marc.glisse@inria.fr>
Tue, 4 Jun 2019 20:39:32 +0000 (22:39 +0200)
committerMarc Glisse <glisse@gcc.gnu.org>
Tue, 4 Jun 2019 20:39:32 +0000 (20:39 +0000)
2019-06-04  Marc Glisse  <marc.glisse@inria.fr>

* tree-ssa-loop-niter.c (number_of_iterations_ne): Skip
computations when step is 1.

From-SVN: r271926

gcc/ChangeLog
gcc/tree-ssa-loop-niter.c

index c7af3457858a9fafaf689c5e9df322b00a606b43..30febc6fecc006beaca68dbb126ab441265b6789 100644 (file)
@@ -1,3 +1,8 @@
+2019-06-04  Marc Glisse  <marc.glisse@inria.fr>
+
+       * tree-ssa-loop-niter.c (number_of_iterations_ne): Skip
+       computations when step is 1.
+
 2019-06-04  Segher Boessenkool  <segher@kernel.crashing.org>
 
        * config/rs6000/constraints.md (define_register_constraint "wf"):
index 470b6a295be5b65e516e4794bbc8a5bbe588aa46..8cf8ef92b01b33a09b9082fc0b5dfec2386f52a2 100644 (file)
@@ -1125,8 +1125,15 @@ number_of_iterations_ne (struct loop *loop, tree type, affine_iv *iv,
     }
 
   c = fold_build2 (EXACT_DIV_EXPR, niter_type, c, d);
-  tmp = fold_build2 (MULT_EXPR, niter_type, c, inverse (s, bound));
-  niter->niter = fold_build2 (BIT_AND_EXPR, niter_type, tmp, bound);
+  if (integer_onep (s))
+    {
+      niter->niter = c;
+    }
+  else
+    {
+      tmp = fold_build2 (MULT_EXPR, niter_type, c, inverse (s, bound));
+      niter->niter = fold_build2 (BIT_AND_EXPR, niter_type, tmp, bound);
+    }
   return true;
 }