From mboxrd@z Thu Jan 1 00:00:00 1970 From: Richard Henderson To: Corey Minyard Cc: gcc@gcc.gnu.org Subject: Re: Loop optimization bug with Ada front end on PPC (and probably Alpha) Date: Mon, 26 Nov 2001 13:49:00 -0000 Message-ID: <20011126134922.A24167@redhat.com> References: <3BFCA770.5070304@acm.org> <20011124124100.A2485@redhat.com> <3C0179C5.2090002@acm.org> <20011125175500.A11474@redhat.com> <3C0274ED.7000708@acm.org> X-SW-Source: 2001-11/msg01289.html Message-ID: <20011126134900.5HlMmAkAMeW3yf6PI-QpfK0n04_baWOVk5aCi7fhuwg@z> 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;