From 46e58e180d6ab1fa37acc96f0b8cbf569bbf4105 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Mon, 9 Apr 2018 13:27:33 +0000 Subject: [PATCH] re PR tree-optimization/85284 (Loop miscompilation starting with r238367) 2018-04-09 Richard Biener PR tree-optimization/85284 * tree-ssa-loop-niter.c (number_of_iterations_exit_assumptions): Only use the niter constraining form of simple_iv when the exit is always executed. * gcc.dg/torture/pr85284.c: New testcase. From-SVN: r259234 --- gcc/ChangeLog | 7 +++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/torture/pr85284.c | 20 ++++++++++++++++++++ gcc/tree-ssa-loop-niter.c | 4 ++-- 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr85284.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 165b968b062..6d0a2692bef 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2018-04-09 Richard Biener + + PR tree-optimization/85284 + * tree-ssa-loop-niter.c (number_of_iterations_exit_assumptions): + Only use the niter constraining form of simple_iv when the exit + is always executed. + 2018-04-09 Tom de Vries PR target/84041 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f89ddfe7e9a..6798e3b4b87 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-04-09 Richard Biener + + PR tree-optimization/85284 + * gcc.dg/torture/pr85284.c: New testcase. + 2018-04-09 Andrey Belevantsev PR rtl-optimization/80463 diff --git a/gcc/testsuite/gcc.dg/torture/pr85284.c b/gcc/testsuite/gcc.dg/torture/pr85284.c new file mode 100644 index 00000000000..80e2c5b247b --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr85284.c @@ -0,0 +1,20 @@ +/* { dg-do run } */ + +static int p[48], v; + +int +main () +{ + p[32] = 1; + for (int i = 48; i--;) + { + if (!p[i]) + continue; + if ((i & 7) > 2) + break; + v = i & 1; + } + if (v != 0) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-ssa-loop-niter.c b/gcc/tree-ssa-loop-niter.c index fa49abf8d3b..7a54c5f1e62 100644 --- a/gcc/tree-ssa-loop-niter.c +++ b/gcc/tree-ssa-loop-niter.c @@ -2356,11 +2356,11 @@ number_of_iterations_exit_assumptions (struct loop *loop, edge exit, tree iv0_niters = NULL_TREE; if (!simple_iv_with_niters (loop, loop_containing_stmt (stmt), - op0, &iv0, &iv0_niters, false)) + op0, &iv0, safe ? &iv0_niters : NULL, false)) return false; tree iv1_niters = NULL_TREE; if (!simple_iv_with_niters (loop, loop_containing_stmt (stmt), - op1, &iv1, &iv1_niters, false)) + op1, &iv1, safe ? &iv1_niters : NULL, false)) return false; /* Give up on complicated case. */ if (iv0_niters && iv1_niters) -- 2.30.2