By the way, here is one case I tested where I was surprised GCC was not
more aggressive:

  extern void bar();
  int foo(int *i) {
    if(*i) bar();
    return *i;
  }

With GCC 4.4.1 -O3 (Ubuntu, x86-64) this reloads *i if bar is called.  I
suppose you have to allow that either "i" or "*i" is accessible as a
global.  But this is a pretty big bummer, because it means that any
function call forces reloads of any data that was read from a pointer.
"restrict" doesn't help here, nor does "const".  The only way to prevent
these reloads is to manually read the data into stack variable(s):

  extern void bar();
  int foo(int *i) {
    int i_val = *i;
    if(i_val) bar();
    return i_val;
  }

Josh

Reply via email to