aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-loop-niter.c
diff options
context:
space:
mode:
authorBin Cheng <bin.cheng@arm.com>2017-06-29 10:41:28 +0000
committerBin Cheng <amker@gcc.gnu.org>2017-06-29 10:41:28 +0000
commit6cd83bec4b76e19175a425b7e1841d9c5d0d164e (patch)
treec6e71e3aaba5005f83a4159c4ed5f4696d06f7d8 /gcc/tree-ssa-loop-niter.c
parenta7c9a3042453642fd220e01b2063307cd479472a (diff)
downloadgcc-6cd83bec4b76e19175a425b7e1841d9c5d0d164e.zip
gcc-6cd83bec4b76e19175a425b7e1841d9c5d0d164e.tar.gz
gcc-6cd83bec4b76e19175a425b7e1841d9c5d0d164e.tar.bz2
re PR tree-optimization/81196 (Number of iterations found for p!=q but not for p<q)
PR tree-optimization/81196 * tree-ssa-loop-niter.c (number_of_iterations_cond): Handle loop exit condition comparing two IVs. gcc/testsuite * gcc.dg/vect/pr81196.c: New. From-SVN: r249778
Diffstat (limited to 'gcc/tree-ssa-loop-niter.c')
-rw-r--r--gcc/tree-ssa-loop-niter.c30
1 files changed, 23 insertions, 7 deletions
diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c
index 848e812..5a7cab5 100644
--- a/gcc/tree-ssa-loop-niter.c
+++ b/gcc/tree-ssa-loop-niter.c
@@ -1668,18 +1668,34 @@ number_of_iterations_cond (struct loop *loop,
exit_must_be_taken = true;
}
- /* We can handle the case when neither of the sides of the comparison is
- invariant, provided that the test is NE_EXPR. This rarely occurs in
- practice, but it is simple enough to manage. */
+ /* We can handle cases which neither of the sides of the comparison is
+ invariant:
+
+ {iv0.base, iv0.step} cmp_code {iv1.base, iv1.step}
+ as if:
+ {iv0.base, iv0.step - iv1.step} cmp_code {iv1.base, 0}
+
+ provided that either below condition is satisfied:
+
+ a) the test is NE_EXPR;
+ b) iv0.step - iv1.step is positive integer.
+
+ This rarely occurs in practice, but it is simple enough to manage. */
if (!integer_zerop (iv0->step) && !integer_zerop (iv1->step))
{
tree step_type = POINTER_TYPE_P (type) ? sizetype : type;
- if (code != NE_EXPR)
+ tree step = fold_binary_to_constant (MINUS_EXPR, step_type,
+ iv0->step, iv1->step);
+
+ /* No need to check sign of the new step since below code takes care
+ of this well. */
+ if (code != NE_EXPR && TREE_CODE (step) != INTEGER_CST)
return false;
- iv0->step = fold_binary_to_constant (MINUS_EXPR, step_type,
- iv0->step, iv1->step);
- iv0->no_overflow = false;
+ iv0->step = step;
+ if (!POINTER_TYPE_P (type))
+ iv0->no_overflow = false;
+
iv1->step = build_int_cst (step_type, 0);
iv1->no_overflow = true;
}