bright@Data-IO.COM (Walter Bright) (01/12/88)
In article <517@cresswell.quintus.UUCP> ok@quintus.UUCP (Richard A. O'Keefe) writes: <In article <11189@brl-adm.ARPA>, TLIMONCE%DREW.BITNET@CUNYVM.CUNY.EDU writes: << noalias int i; << for (i=0; i<100; i++) {...anything...} << the default is the "safe" method. << If the compiler notices that I don't modify i in the loop < *********************** <If the compiler is smart enough to notice that the loop body does not <change 'i', why do you need to tell it 'noalias'? A *local* variable <whose address is never taken cannot possibly be aliased, because there <is no other *legal* way to get at it. <Just how much of a problem do we really have here, anyway? <The problem of aliasing is a problem of having multiple legal access <paths to the same variable. How often is the controlled variable of <a loop global? How often does it have its address taken? I have only run across two general cases where people have used globals for loop indices: 1. The programmer was new to C. 2. So the variable could be accessed by a debugger. Neither of those cases warrants adding a new keyword. The primary use of noalias is to soften the following worst cases: if (an assignment to a global or static occurs || an assignment through a pointer occurs || a function is called for which we have no information) { Mark all global and static variables as possibly modified; Mark all indirect references as possibly modified; } Marking an expression as being possibly modified means that if its value is in a register, it must be reloaded. Also, it prevents common subexpressions from being formed across the modification point. Since C is a 'pointy' language, in order to improve code generation, a real wad of 'noalias' casts would have to be used. I suspect people won't use it because its ugly. Does anyone have any statistics on the code generation improvement if 'noalias' is used to the max? I suspect it may not be worth the effort. My vote is to dump the noalias keyword. P.S. I have written a globally optimizing compiler (Datalight C) that does full flow analysis, and uses the algorithm above.