This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Loop optimization bug with Ada front end on PPC (and probably Alpha)
On Mon, Nov 26, 2001 at 10:59:25AM -0600, Corey Minyard wrote:
> Not all loops have loop->top set in this situation, because that's only
> set in bottom entry loops, it seems.
Oh, duh. Look at scan_loop: loop->top is set in exactly the condition
that we're interested in and no other. That simplifies the code in
loop_iterations greatly.
ia64 bootstrap underway.
r~
Index: unroll.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/unroll.c,v
retrieving revision 1.147
diff -c -p -d -r1.147 unroll.c
*** unroll.c 2001/11/21 00:50:56 1.147
--- unroll.c 2001/11/26 21:46:30
*************** loop_iterations (loop)
*** 3480,3485 ****
--- 3480,3486 ----
int unsigned_p, compare_dir, final_larger;
rtx last_loop_insn;
rtx reg_term;
+ rtx insn;
struct iv_class *bl;
loop_info->n_iterations = 0;
*************** loop_iterations (loop)
*** 3705,3710 ****
--- 3706,3747 ----
if (initial_value == 0)
return 0;
+
+ /* Some code transformations can result in code akin to
+
+ LOOP_BEG
+ goto start;
+ top:
+ i++;
+ start:
+ ...
+ LOOP_CONT
+ if (i < n) goto top;
+ LOOP_END
+
+ We'll have already detected this form of loop in scan_loop,
+ and set loop->top and loop->scan_start appropriately.
+
+ In this situation, we skip the increment the first time through
+ the loop, which results in an incorrect estimate of the number
+ of iterations. As we did for GIVs above, adjust the initial value
+ to compensate. */
+
+ if (loop->top
+ && reg_set_between_p (bl->biv->src_reg, loop->top, loop->scan_start))
+ {
+ if (loop_dump_stream)
+ fprintf (loop_dump_stream,
+ "Loop iterations: Basic induction var skips initial incr.\n");
+ if (GET_CODE (increment) != CONST_INT)
+ {
+ if (loop_dump_stream)
+ fprintf (loop_dump_stream,
+ "Loop iterations: Can't adjust with non-constant incr.\n");
+ return 0;
+ }
+ initial_value = plus_constant (initial_value, -INTVAL (increment));
+ }
unsigned_p = 0;
off_by_one = 0;