Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cbmvax!jesup From: jesup@cbmvax.commodore.com (Randell Jesup) Newsgroups: comp.arch Subject: Re: Optimising C compiler question Message-ID: <20633@cbmvax.commodore.com> Date: 15 Apr 91 07:52:09 GMT References: <1991Apr8.193155.3911@vax5.cit.cornell.edu> <20715@lanl.gov> Reply-To: jesup@cbmvax.commodore.com (Randell Jesup) Distribution: comp Organization: Commodore, West Chester, PA Lines: 50 In article <20715@lanl.gov> jlg@cochiti.lanl.gov (Jim Giles) writes: >I see them all the time. Most of my local variables in C code that I >write are register. I wish it were the default mode for all automatic >variables. According to the ANSI standard, the only thing that the >register attribute means is that you can't point to that variable (that >is, you can't use the 'address-of' operator (&) on them). This means >that a smart compiler can optimize them is ways that it otherwise can't. A smart compiler notices that & is never used on the variable, removing that reason for putting 'register' everywhere. >|> Are modern RISC compilers sufficiently good that they automatically make >|> sensible choice of register variables? [...] > >No. At least I've not seen any that good. The problem is that _any_ >use of the address of a variable requires turning off the register >atrtribute - even call by reference to a procedure. Unless the compiler >keeps track of all uses of all variables, it can't identify those that >can be made register variables. Most compilers optimize on the 'basic >block' level - and don't know much about the use of variables outside >that level (except for the declaraction). Still, as you say, a _really_ >good compiler would make the register attribute redundant. Umm, maybe you've spent too much time in the MSDOS world, or something equally horrid. In any case, modern compilers for even things like the Amiga (680x0) do global optimization, including register selection (and have for some time). Sometimes you can do better than they do, but they usually are as good or better. I no longer even bother with register except in extreme cases - and I'm more likely to drop to assembler if I need speed that much. >However, most really good modern compilers will already know whether >a variable is 'live' on exit or not. If you don't use the variable >anywhere else in the code, a really good compiler will not do any >redundant stores. In fact, even if you _do_ use it elsewhere in the >code, but all paths to the additional use contain an assignment to the >variable, the compiler will still not do the store. (Liveness analysis >is more often available than the global data flow required to identify >a variable which can be given register attribute. I don't know why this >is, the same mechanisms could carry the additional information.) I think you're underestimating the state of compilers out there. -- Randell Jesup, Keeper of AmigaDos, Commodore Engineering. {uunet|rutgers}!cbmvax!jesup, jesup@cbmvax.commodore.com BIX: rjesup Disclaimer: Nothing I say is anything other than my personal opinion. Thus spake the Master Ninjei: "To program a million-line operating system is easy, to change a man's temperament is more difficult." (From "The Zen of Programming") ;-)