Dear Wizard:
This is a really C question, but as it concerns a #pragma (or rather
the lack of one) it is specific to DEC C.
Consider the following function definition
void f(float * a, const float * const b)
{
*++a = *b;
*++a = *b;
}
for which DEC C V5.0-003 (with /OPTIMIZE=LEVEL=4) produces the
following code:
ADDL a, 4, a
LDF F0, (R17)
STF F0, (R16)
ADDL a, 4, R16
LDF F1, (R17)
STF F1, (R16)
RET R26
Observe that *b is loaded twice, as it must be because according the C
semantics b and a could point to the same location. There is
apparently no way to tell DEC C that a and b will always point at
disjoint regions of memory; it is not expressible within the language
itself, although some compilers provide a #pragma to do so.
It is of course very easy to rewrite the trivial example above to
avoid the problem, but there are many more interesting examples where
it seems harder to find such a solution. For instance, consider matrix
multiplication where I would like to tell the compiler that the result
matrix is disjoint from the argument matrices. At present the
generated code contains lots of unnecessary loads which reduces the
performance considerably, which is especially galling as the result
obtained using the obvious algorithm (without a matrix temporary) is
wrong if the result and arguments are not disjoint anyhow!
I could copy the arguments into local temporaries, but then I run into
a whole lot of problems, such as that I might inhibit optimizations
like loop unrolling and instruction scheduling, and that I need to
allocate the memory for the temporaries somewhere (which is not so
easy if the number of temporaries is not known at compile time).
I welcome your suggestions, as I find that this problem makes it hard
approach the peak floating point performance of an Alpha processor
using DEC C.