2 ms·
I like your detailed example, but wouldn't a slightly kinder but equally optimizing compiler simply add a conditional before the load: if (max > 0) { int
by nkurz 12y ago
I like your detailed example, but wouldn't a slightly kinder but equally optimizing compiler simply add a conditional before the load:
if (max > 0) {
int i = max;
int tmp = p[0].foo;
do {
bar += tmp;
} while (--i);
}
I'd even argue the assembly is slightly better when interpreted this way, since branch prediction will tend execute the load or not as appropriate, rather than potentially taking a unnecessary TLB miss for a load that's never used.