"Richard Guenther" <[EMAIL PROTECTED]> writes: > > I hope we're not trying to support such w/o volatile counter. Whatever > POSIX says, this would pessimize generic code too much.
It is dubious this transformation is an optimization at all for memory. e.g. consider the case counter is not in cache. You'll add an cache miss which will be 2-3 degrees of magnitude more costly than what you can safe by not jumping. Full cache misses are so expensive that even when they happen rarely they still hurt a lot. There might be a case for doing it on memory when you can pretty much guarantee the variable is in L1 (e.g. it is in the stack frame and you only got a very small stack frame) or only in a register. But for other cases it's likely better to not do it at all. BTW there is a cache friendly (and incidentially thread-safe) alternative way to eliminate the jump transformation when the CPU has CMOV available. You can use int dummy; // on stack, likely in L1 int *ptr; ptr = &dummy; if (cond) // can be implemented jumpless using CMOV ptr = &counter; *ptr++; This will take more registers though. -Andi