On April 27, 2017 8:47:18 PM GMT+02:00, Steve Ellcey <sell...@cavium.com> wrote: >I have a question about the GCC loop structure. I am trying to >identify the >induction variable for a for loop and I don't see how to do that. > >For example, if I have: > > int foo(int *a, int *b, int *c, int *d, int *e, int *f, int n) > { > int i; > for (i = 0; i < n; i++) { > a[i] = b[i] + c[i]; > d[i] = e[i] * f[i]; > } > } > >I basically want to identify 'i' as the IV and look at its uses inside >the >loop. > >I can look at the control_ivs in the loop structure and I see: > >base is: ><integer_cst 0x7f1d0d29d090 type <integer_type 0x7f1d0d2985e8 int> >constant 1> >step is: ><integer_cst 0x7f1d0d29d090 type <integer_type 0x7f1d0d2985e8 int> >constant 1> > >But it doesn't say what is being set to base or what is being increased >by >step in each loop iteration. (I am also not sure why base is 1 and not >0.) > >Does this refer to a psuedo-IV or something instead of a real SSA >variable >that appears in the tree? How would I identify 'i' as the IV for this >loop? Do I need to look at the loop header and latch and see what the >header sets and what the latch checks to identify the variable?
I think you want to look at all loop header PHIs. The PHI results that satisfy simple_iv should be those you are interested in. Richard. >Steve Ellcey >sell...@cavium.com