Topic: Optimizing empty loops (was: common...)
Author: fjh@munta.cs.mu.OZ.AU (Fergus Henderson)
Date: Mon, 27 Jun 1994 17:06:45 GMT Raw View
maxtal@physics.su.OZ.AU (John Max Skaller) writes:
>fjh@munta.cs.mu.OZ.AU (Fergus Henderson) writes:
>>*Any* code without side effects can be optimized
>>away or inserted at will.
>
> That statement is "apparently" correct.
>(Dont you DARE optimise away my timing loops! :-))
A good optimizing compiler should at least provide an option
to optimize loops with empty bodies, IMHO.
It's certainly allowed, and it can indeed be useful.
Consider the following example:
template <class T>
void Array::~Array() {
for (int i = 0; i < this->elem_count; i++) {
this->elem[i].~T();
}
free(this->elem);
}
In the case of Array<int>, the body of the loop is a call to int::~int(),
which is a no-op. I would hope that a good optimizing compiler
would be capable of optimizing this loop away.
--
Fergus Henderson - fjh@munta.cs.mu.oz.au