News for hackers. Stuff that matters.
Re:Three proposals for the C standard WG14 by palotasb on Thursday June 21, 2018 @04:29AM (#17363159)
Isn't the reference compiler with trivial compilation equivalent to trying to make all UB implementation-defined where the implementation is the "trivial compilation"? For example this would preclude optimization based on aliasing rules which a lot of tight loops rely on.

  float max (float f[], int length, int* max_index) {
    float max_value = -FLT_MAX;
    *max_index = -1;
    for (int i = 0; i < length; i++) {
      if (max_value < f[i]) {
         *max_index= i;
         max_value = f[i];
      }
    }
    return max_value;
  }
Take the code above. It obviously has a well-defined trivial compilation implementation even for cases where max_index aliases an element of the f[] array. There is a good reason that implementations are allowed to assume that doesn't happen: it produces better code in the case where the program has no bugs. Otherwise even at -O3, the implementation would have to read f[i] twice from memory as the value might have changed when *max_index was written if it wants the same behavior as the "trivial compilation" implementation.

There are no comments on this comment yet.