aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPat Haugen <pthaugen@us.ibm.com>2016-11-10 18:55:57 +0000
committerPat Haugen <pthaugen@gcc.gnu.org>2016-11-10 18:55:57 +0000
commit8d34bfa865fb527b6a3569528656e2dc8af592e0 (patch)
tree223b62a9c66bd4b015116cdb4548e792f4fe43a6 /gcc
parenta1566696653132892d629525644c2c63da8dab87 (diff)
downloadgcc-8d34bfa865fb527b6a3569528656e2dc8af592e0.zip
gcc-8d34bfa865fb527b6a3569528656e2dc8af592e0.tar.gz
gcc-8d34bfa865fb527b6a3569528656e2dc8af592e0.tar.bz2
re PR rtl-optimization/78241 (wrong code with -funroll-loops)
PR rtl-optimization/78241 * loop-unroll.c (unroll_loop_runtime_iterations): Don't adjust 'niter', but emit initial peel copy if niter expr is not reliable. * gcc.dg/pr78241.c: New test. From-SVN: r242047
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/loop-unroll.c9
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/pr78241.c20
4 files changed, 36 insertions, 4 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 66586e4..66ff361 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2016-11-10 Pat Haugen <pthaugen@us.ibm.com>
+
+ PR rtl-optimization/78241
+ * loop-unroll.c (unroll_loop_runtime_iterations): Don't adjust 'niter', but
+ emit initial peel copy if niter expr is not reliable.
+
2016-11-10 Segher Boessenkool <segher@kernel.crashing.org>
* dwarf2cfi.c (dump_cfi_row): Add forward declaration.
diff --git a/gcc/loop-unroll.c b/gcc/loop-unroll.c
index 91118a3..760445e 100644
--- a/gcc/loop-unroll.c
+++ b/gcc/loop-unroll.c
@@ -918,9 +918,10 @@ unroll_loop_runtime_iterations (struct loop *loop)
if (tmp != niter)
emit_move_insn (niter, tmp);
- /* For loops that exit at end, add one to niter to account for first pass
- through loop body before reaching exit test. */
- if (exit_at_end)
+ /* For loops that exit at end and whose number of iterations is reliable,
+ add one to niter to account for first pass through loop body before
+ reaching exit test. */
+ if (exit_at_end && !desc->noloop_assumptions)
{
niter = expand_simple_binop (desc->mode, PLUS,
niter, const1_rtx,
@@ -946,7 +947,7 @@ unroll_loop_runtime_iterations (struct loop *loop)
auto_sbitmap wont_exit (max_unroll + 2);
- if (extra_zero_check)
+ if (extra_zero_check || desc->noloop_assumptions)
{
/* Peel the first copy of loop body. Leave the exit test if the number
of iterations is not reliable. Also record the place of the extra zero
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index d522e24..b3f9442 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2016-11-10 Pat Haugen <pthaugen@us.ibm.com>
+
+ PR rtl-optimization/78241
+ * gcc.dg/pr78241.c: New test.
+
2016-11-10 Jakub Jelinek <jakub@redhat.com>
* gfortran.dg/openmp-define-3.f90: Expect 201511 instead of
diff --git a/gcc/testsuite/gcc.dg/pr78241.c b/gcc/testsuite/gcc.dg/pr78241.c
new file mode 100644
index 0000000..b99dfca
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr78241.c
@@ -0,0 +1,20 @@
+/* { dg-do run } */
+/* { dg-options "-Og -funroll-loops" } */
+
+static __attribute__((noinline, noclone)) unsigned
+foo (unsigned x)
+{
+ do
+ x++;
+ while (x <= 15);
+ return x;
+}
+
+int main ()
+{
+ unsigned x = foo (-2);
+ if (x != (unsigned)-1)
+ __builtin_abort();
+ return 0;
+}
+