This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] PR78241, fix loop unroller when niter expr is not reliable
- From: Pat Haugen <pthaugen at linux dot vnet dot ibm dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Jeff Law <law at redhat dot com>
- Date: Wed, 9 Nov 2016 16:13:35 -0600
- Subject: [PATCH] PR78241, fix loop unroller when niter expr is not reliable
- Authentication-results: sourceware.org; auth=none
The following fixes a problem introduced by my earlier loop unroller patch, https://gcc.gnu.org/ml/gcc-patches/2016-09/msg01612.html. In instances where the niter expr is not reliable we need to still emit an initial peel copy of the loop.
Bootstrap/regtest on powerpc64le with no new regressions. Ok for trunk?
-Pat
2016-11-09 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.
testsuite/ChangeLog:
2016-11-09 Pat Haugen <pthaugen@us.ibm.com>
* gcc.dg/pr78241.c: New test.
Index: gcc/loop-unroll.c
===================================================================
--- gcc/loop-unroll.c (revision 241821)
+++ gcc/loop-unroll.c (working copy)
@@ -918,9 +918,10 @@ unroll_loop_runtime_iterations (struct l
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 l
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
Index: gcc/testsuite/gcc.dg/pr78241.c
===================================================================
--- gcc/testsuite/gcc.dg/pr78241.c (revision 0)
+++ gcc/testsuite/gcc.dg/pr78241.c (working copy)
@@ -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;
+}
+