This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Weird behavior in ivopts code


Hello,

> Which appears to walk down the array and try and choose better IV sets.
> Since it walks down the IV array, which is in SSA_NAME_VERSION order.
> Thus two loops which are equivalent in all ways except that they use
> different SSA_NAME_VERSIONs can get different IV sets.
> 
> Anyway, the instability of the IV opts code when presented with loops
> that differ only in the version #s in the SSA_NAMEs they use is really
> getting in the way of understanding the performance impact of the
> new jump threading code.  I would expect this instability to also make
> it difficult to analyze the IVopts in general.

there's not much to do about the matter.  The choice of ivs in ivopts is
just a heuristics (and this cannot be changed, due to compiler
performance reasons), and as such it is prone to such instabilities.
In fact, both choices of ivs make sense, and they have the same cost
w.r. to the cost function used by ivopts.

Anyway, in this particular case, the patch below should make ivopts
to prefer the choice of preserving the variable 'i' (which is better
from the point of preserving debugging information).

Zdenek

Index: tree-ssa-loop-ivopts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-loop-ivopts.c,v
retrieving revision 2.21
diff -c -3 -p -r2.21 tree-ssa-loop-ivopts.c
*** tree-ssa-loop-ivopts.c	27 Oct 2004 20:27:20 -0000	2.21
--- tree-ssa-loop-ivopts.c	27 Oct 2004 20:30:19 -0000
*************** determine_iv_cost (struct ivopts_data *d
*** 3326,3333 ****
  
    cand->cost = cost_step + cost_base / AVG_LOOP_NITER (current_loop);
  
!   /* Prefer the original iv unless we may gain something by replacing it.  */
!   if (cand->pos == IP_ORIGINAL)
      cand->cost--;
    
    /* Prefer not to insert statements into latch unless there are some
--- 3327,3337 ----
  
    cand->cost = cost_step + cost_base / AVG_LOOP_NITER (current_loop);
  
!   /* Prefer the original iv unless we may gain something by replacing it;
!      this is not really relevant for artificial ivs created by other
!      passes.  */
!   if (cand->pos == IP_ORIGINAL
!       && !DECL_ARTIFICIAL (SSA_NAME_VAR (cand->var_before)))
      cand->cost--;
    
    /* Prefer not to insert statements into latch unless there are some


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]