public inbox for gcc-prs@sourceware.org help / color / mirror / Atom feed
From: Alan Modra <amodra@bigpond.net.au> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, Subject: Re: optimization/7120: Run once loop should *always* be unrolled Date: Wed, 26 Jun 2002 03:06:00 -0000 [thread overview] Message-ID: <20020626083602.30415.qmail@sources.redhat.com> (raw) The following reply was made to PR optimization/7120; it has been noted by GNATS. From: Alan Modra <amodra@bigpond.net.au> To: davem@gcc.gnu.org, gcc-bugs@gcc.gnu.org, nobody@gcc.gnu.org, rth@twiddle.net, rusty@rustcorp.com.au, gcc-gnats@gcc.gnu.org, gcc-patches@gcc.gnu.org Cc: Subject: Re: optimization/7120: Run once loop should *always* be unrolled Date: Wed, 26 Jun 2002 18:02:10 +0930 On Wed, Jun 26, 2002 at 01:17:00PM +0930, Alan Modra wrote: > Bah, that's too simplistic. Patch withdrawn. This one is better. Handles horrible loops like: extern int *arr; int i; i = 0; do { arr[i] = 0; i++; } while (i == 1); I'm also setting loop_info->final_value and loop_info->final_equiv_value as they were reset to zero earlier. bootstrapped and regression tested i686-linux. * unroll.c (loop_iterations): Handle EQ loops. Index: gcc/unroll.c =================================================================== RCS file: /cvs/gcc/gcc/gcc/unroll.c,v retrieving revision 1.168 diff -u -p -r1.168 unroll.c --- gcc/unroll.c 15 Jun 2002 01:10:49 -0000 1.168 +++ gcc/unroll.c 26 Jun 2002 04:58:40 -0000 @@ -3941,12 +3941,6 @@ loop_iterations (loop) } return 0; } - else if (comparison_code == EQ) - { - if (loop_dump_stream) - fprintf (loop_dump_stream, "Loop iterations: EQ comparison loop.\n"); - return 0; - } else if (GET_CODE (final_value) != CONST_INT) { if (loop_dump_stream) @@ -3957,6 +3951,34 @@ loop_iterations (loop) fprintf (loop_dump_stream, ".\n"); } return 0; + } + else if (comparison_code == EQ) + { + if (loop_dump_stream) + fprintf (loop_dump_stream, "Loop iterations: EQ comparison loop.\n"); + + if (((INTVAL (initial_value) + INTVAL (increment)) + & (((unsigned HOST_WIDE_INT) 1 + << (GET_MODE_BITSIZE (GET_MODE (iteration_var)) - 1) + << 1) - 1)) == INTVAL (final_value)) + { + /* The iterator value once through the loop is equal to the + comparision value. Either we have an infinite loop, or + we'll loop twice. */ + if (INTVAL (increment) == 0) + return 0; + loop_info->n_iterations = 2; + } + else + loop_info->n_iterations = 1; + + loop_info->final_value + = plus_constant (loop_info->initial_value, + loop_info->n_iterations * INTVAL (increment)); + loop_info->final_equiv_value + = GEN_INT (INTVAL (initial_value) + + loop_info->n_iterations * INTVAL (increment)); + return loop_info->n_iterations; } /* Final_larger is 1 if final larger, 0 if they are equal, otherwise -1. */ -- Alan Modra IBM OzLabs - Linux Technology Centre
next reply other threads:[~2002-06-26 8:36 UTC|newest] Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top 2002-06-26 3:06 Alan Modra [this message] -- strict thread matches above, loose matches on Subject: below -- 2002-06-28 18:15 Richard Henderson 2002-06-26 19:26 Alan Modra 2002-06-26 12:58 Richard Henderson 2002-06-25 21:29 Alan Modra 2002-06-25 20:56 Alan Modra 2002-06-25 9:26 davem 2002-06-25 9:21 rusty
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20020626083602.30415.qmail@sources.redhat.com \ --to=amodra@bigpond.net.au \ --cc=gcc-prs@gcc.gnu.org \ --cc=nobody@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).