|[9 earlier articles]|
|Re: programmer optimizations? email@example.com (Stefan Monnier) (1995-01-21)|
|Re: programmer optimizations? firstname.lastname@example.org (Dave Gillespie) (1995-01-11)|
|Re: programmer optimizations? email@example.com (David Toland) (1995-01-11)|
|Re: programmer optimizations? firstname.lastname@example.org (1995-01-23)|
|Re: programmer optimizations? email@example.com (1995-01-27)|
|Re: programmer optimizations? firstname.lastname@example.org (1995-01-31)|
|Re: programmer optimizations? c1veeru@WATSON.IBM.COM (Virendra K. Mehta) (1995-02-02)|
|Re: programmer optimizations? email@example.com (1995-02-01)|
|Re: programmer optimizations? firstname.lastname@example.org (1995-02-01)|
|Re: programmer optimizations? email@example.com (1995-02-02)|
|Re: programmer optimizations? firstname.lastname@example.org (Ronald F. Guilmette) (1995-02-04)|
|From:||"Virendra K. Mehta" <c1veeru@WATSON.IBM.COM>|
|Date:||Thu, 2 Feb 1995 05:58:45 GMT|
[ Christopher Glaeser penned : ]
|o| > > replacing (n / 4)
|o| > > by (n >> 2)
|o| > Unfortunately it seems you cannot always trust the compiler writers
|o| > to do the right thing here.
This brings to mind another related optimization. A compiler cannot optimize
based on a pointer that has come in as a formal parameter, or which gets
passed to a function. For example, consider
*pi = 1;
if (*pi == 1)
Here, it can't be assumed that pi would not have been modified by the call to
fn2. Thus the compiler cannot do away with the 'if' check (this is a very
simplified example). This is further reinforced if 'pi' is passed as an
argument to fn2. Technically speaking, pi is placed on an alias list. Same
happens for an auto variable, if its address is taken once. Most optimizations
on it are suspended thereafter.
This can be pretty frustrating if there are a lot of pointer variables passed
to a function and used deep inside a loop. The compiler refuses to perform
many simple common-subexpression-elimination optimizations and accesses memory
repeatedly when the contents can be placed in a register once for all. The
problem here is that the programmer KNOWS that the variable need not be placed
on the alias list. I think there should be some way for him to be able to
communicate this to the compiler. (I've been trying to optimize a lot of such
code currently, part of a scientific software).
I remember reading somewhere that C had a stillborn reserved word 'noalias'.
Was it supposed to convey the same meaning ? Why was it discontinued and how
good an idea would it be to revive it ?
Is there a general set of guidelines that should be followed by programmers to
ensure these optimizations ? (I know that compilers can't take a chance there,
unless a hint is given to them by the programmer).
Comments anyone ?
Virendra K Mehta email@example.com
Wipro Systems Ltd. firstname.lastname@example.org
[There have been a variety of C extensions proposed for "noalias" or
"restricted" pointers. Noalias failed to make it into the standard because
they couldn't get a clean enough definition of it in the time frame they had.
Restricted pointers may show up in C9X. -John]
Return to the
Search the comp.compilers archives again.