From 4a28e1f11335c771e215d0cdbae630828c0acaf2 Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Tue, 4 Jun 2019 22:39:32 +0200 Subject: [PATCH] Simplify loop size when step=1 2019-06-04 Marc Glisse * tree-ssa-loop-niter.c (number_of_iterations_ne): Skip computations when step is 1. From-SVN: r271926 --- gcc/ChangeLog | 5 +++++ gcc/tree-ssa-loop-niter.c | 11 +++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index c7af3457858..30febc6fecc 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2019-06-04 Marc Glisse + + * tree-ssa-loop-niter.c (number_of_iterations_ne): Skip + computations when step is 1. + 2019-06-04 Segher Boessenkool * config/rs6000/constraints.md (define_register_constraint "wf"): diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c index 470b6a295be..8cf8ef92b01 100644 --- a/gcc/tree-ssa-loop-niter.c +++ b/gcc/tree-ssa-loop-niter.c @@ -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; } -- 2.30.2