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)
I've got a hack that appears to work -- the start label
must be before the CONT marker.
I'm nervous about this patch now, because I don't think
we really understand the exact situation in which the
original problem can ocurr. But as I've as yet got no
further failures to look at, I'll commit it anyway.
r~
* unroll.c (loop_iterations): Detect one situation in which we
overestimate the number of iterations.
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/27 18:27:08
*************** loop_iterations (loop)
*** 3706,3711 ****
--- 3706,3746 ----
if (initial_value == 0)
return 0;
+ /* Some code transformations can result in code akin to
+
+ tmp = i + 1;
+ ...
+ goto scan_start;
+ top:
+ tmp = tmp + 1;
+ scan_start:
+ i = tmp;
+ if (i < n) goto top;
+
+ 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. Adjust the initial value to compensate. */
+
+ if (loop->scan_start && loop->cont
+ && INSN_LUID (loop->scan_start) < INSN_LUID (loop->cont)
+ && INSN_LUID (bl->biv->insn) < INSN_LUID (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;
switch (comparison_code)