summaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorhubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4>2012-10-20 15:51:16 +0000
committerhubicka <hubicka@138bc75d-0d04-0410-961f-82ee72b054a4>2012-10-20 15:51:16 +0000
commitc8fbcf5814ca7d33e2ed28e487be37e72372c18e (patch)
tree595b4113b43061b69a63c45eb00bbb235517a85d /gcc
parent43780738cd22a2fbea5fd7d8260a76e0c3121f43 (diff)
downloadgcc-c8fbcf5814ca7d33e2ed28e487be37e72372c18e.tar.gz
* gcc.dg/tree-prof/unroll-1.c: New testcase.
* loop-unroll.c (decide_unroll_constant_iterations): Don't perform unrolling for loops with low iterations bounds or estimates. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@192638 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/loop-unroll.c11
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/tree-prof/unroll-1.c24
4 files changed, 42 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 47263fd8232..0403a90eb45 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,10 @@
2012-10-20 Jan Hubicka <jh@suse.cz>
+ * loop-unroll.c (decide_unroll_constant_iterations): Don't
+ perform unrolling for loops with low iterations bounds or estimates.
+
+2012-10-20 Jan Hubicka <jh@suse.cz>
+
* loop-iv.c (iv_number_of_iterations): Record the upper bound
only if there are no further conditions on it.
diff --git a/gcc/loop-unroll.c b/gcc/loop-unroll.c
index 0dd8b0a9d5c..2398e6d6b11 100644
--- a/gcc/loop-unroll.c
+++ b/gcc/loop-unroll.c
@@ -519,6 +519,7 @@ decide_unroll_constant_iterations (struct loop *loop, int flags)
{
unsigned nunroll, nunroll_by_av, best_copies, best_unroll = 0, n_copies, i;
struct niter_desc *desc;
+ double_int iterations;
if (!(flags & UAP_UNROLL))
{
@@ -561,8 +562,14 @@ decide_unroll_constant_iterations (struct loop *loop, int flags)
return;
}
- /* Check whether the loop rolls enough to consider. */
- if (desc->niter < 2 * nunroll)
+ /* Check whether the loop rolls enough to consider.
+ Consult also loop bounds and profile; in the case the loop has more
+ than one exit it may well loop less than determined maximal number
+ of iterations. */
+ if (desc->niter < 2 * nunroll
+ || ((estimated_loop_iterations (loop, &iterations)
+ || max_loop_iterations (loop, &iterations))
+ && iterations.ult (double_int::from_shwi (2 * nunroll))))
{
if (dump_file)
fprintf (dump_file, ";; Not unrolling loop, doesn't roll\n");
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index adb5542de5b..a10971c2553 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2012-10-20 Jan Hubicka <jh@suse.cz>
+
+ * gcc.dg/tree-prof/unroll-1.c: New testcase.
+
2012-10-19 Janus Weil <janus@gcc.gnu.org>
PR fortran/54224
diff --git a/gcc/testsuite/gcc.dg/tree-prof/unroll-1.c b/gcc/testsuite/gcc.dg/tree-prof/unroll-1.c
new file mode 100644
index 00000000000..b1c6b8b2d39
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-prof/unroll-1.c
@@ -0,0 +1,24 @@
+/* { dg-options "-O3 -fdump-rtl-loop2_unroll -funroll-loops -fno-peel-loops" } */
+void abort ();
+
+int a[1000];
+int
+__attribute__ ((noinline))
+t()
+{
+ int i;
+ for (i=0;i<1000;i++)
+ if (!a[i])
+ return 1;
+ abort ();
+}
+main()
+{
+ int i;
+ for (i=0;i<1000;i++)
+ t();
+ return 0;
+}
+/* { dg-final-use { scan-rtl-dump "Considering unrolling loop with constant number of iterations" "loop2_unroll" } } */
+/* { dg-final-use { cleanup-rtl-dump "Not unrolling loop, doesn't roll" } } */
+/* { dg-options "-O3 -fdump-rtl-loop2_unroll -funroll-loops -fno-peel-loops" } */