rtlopt loop unroller question
Zdenek Dvorak
rakdver@atrey.karlin.mff.cuni.cz
Thu Oct 23 21:05:00 GMT 2003
Hello,
> > as I suspected, my favourite piece of cse strikes again. With the
> > patch below, the code produced is much better
>
> First, tnx for your patch; the code is indeed much better!
> However, if we complicate the example a little bit:
>
> {
> int A[N];
> int B[N];
> int C[N];
> int i;
>
> for (i=0; i<N; i++)
> A[i]=B[i]+C[i];
> return A;
> }
>
> we still get the inefficient addressing calculations.
> Using static variables instead of local ones yields
> much better code with or without your patch.
I am not sure what you refer to here (could you please demonstrate on
assembler)?
> > addi r4,r12,4
> > addi r2,r12,8
> > addi r29,r12,12
> > addi r28,r12,16
> > addi r27,r12,20
> > addi r26,r12,24
> > addi r25,r12,28
>
> Finally, we still get redundant adds (compared to old-unroll); can
> something be
> done to fix them too?
I am not sure why these are not propagated to addresses by cse; I
thought it is capable of this kind of magic.
As for loop optimizer -- yes, indeed something can be done; the
induction variable optimization may be rerun after the unrolling (patch
below). But although you will probably like the resulting code, the
problem is that it extremely increases compile time -- 4 times (meaning
time of gcc, not just loop optimizer...); this clearly is a bug, I will
have to investingate.
Zdenek
Index: loop-init.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/loop-init.c,v
retrieving revision 1.1.2.10
diff -c -3 -p -r1.1.2.10 loop-init.c
*** loop-init.c 25 Jul 2003 17:45:00 -0000 1.1.2.10
--- loop-init.c 23 Oct 2003 19:44:04 -0000
*************** loop_optimizer_optimize (struct loops *l
*** 179,184 ****
--- 179,208 ----
if (flag_peel_loops || flag_unroll_loops)
unroll_and_peel_loops (loops);
+ /* Rerun the optimization again, to improve the induction variable usage in
+ the unrolled loops. */
+ if (optimize >= 3 && flag_unroll_loops)
+ {
+ timevar_push (TV_IV_ANAL);
+ initialize_iv_analysis (loops);
+ analyse_induction_variables ();
+ timevar_pop (TV_IV_ANAL);
+
+ loop_avail_regs = xcalloc (loops->num, sizeof (int));
+ ivopt_actions.ivs = NULL;
+ ivopt_actions.replacements = NULL;
+ ivopt_actions.repl_final_value = NULL;
+ if (flag_strength_reduce)
+ detect_strength_reductions (loops, &ivopt_actions);
+ free (loop_avail_regs);
+
+ timevar_push (TV_IV_ANAL);
+ finalize_iv_analysis ();
+ timevar_pop (TV_IV_ANAL);
+
+ execute_strength_reductions (loops, &ivopt_actions);
+ }
+
#ifdef HAVE_doloop_end
if (HAVE_doloop_end && flag_branch_on_count_reg)
doloop_optimize_loops (loops);
More information about the Gcc
mailing list