hoisting loop invariant loads?

ranganath ramachandra ranga@hp.com
Tue Sep 22 11:12:00 GMT 2015


Hello,

With the following code:

----------------------------
  typedef struct {
      int *scores;
      int count;
  } result;
  void sum(result *r)
  {
    int i=0,s=0;
    for (i=0;i<r->count;i++)
    {
      s += r->scores[i];
    }
  }
----------------------------

gcc 4.9.2 (x86_64, aarch64) keeps the load of the pointer r->scores inside the loop.

I am trying to get this load hoisted out of the loop. How can I achieve this?

I've tried:
  -O3
  -fgcse [ -fgcse-lm ]
  -ftree-loop-im
  -ftree-phiprop

Thanks
ranga



More information about the Gcc-help mailing list