Question on aliasing

Henry Spencer henry at utzoo.uucp
Sat Aug 6 03:59:17 AEST 1988


In article <3709 at hcr.UUCP> stacey at hcr.UUCP (Stacey Campbell) writes:
>>They mention that [noalias] will speed up the program. How does this work?
> ...
>	printf("Henry, make sure you correct this if it is a bad example.\n");

What a sneaky way to get me to comment... :-)

>noalias int n;
>
>The optimiser would then calculate (n / 5) once outside the loop, store
>the result in a temporary variable, and use the temporary in the loop
>(but if you declare it noalias, then go ahead and alias it and write to the
>alias, all hell will break loose).

Pretty much so.  The idea behind noalias was, roughly, that if you access a
value via a path including "noalias", the compiler is entitled to cache that
value, possibly even altering the cached copy and writing it back later,
without worrying that the value might have been accessed by another path
which would result in another possibly-altered-and-written-back cached copy.
If such an alternate path exists, the results are anyone's guess.  Getting
all this *precisely* pinned down is harder than it looks, especially in
the presence of arrays (if you pass a pointer to an array element, is this
a path to the whole array?  what if it's a character array that contains
more than one string, and you pass a pointer to one of the strings? etc.).
-- 
MSDOS is not dead, it just     |     Henry Spencer at U of Toronto Zoology
smells that way.               | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.lang.c mailing list