re: register variables in C

wicklund@intellistor.com (Tom Wicklund)
Thu, 23 Apr 1992 18:23:25 GMT

          From comp.compilers

Related articles
register variables in C. eric@pencom.com (1992-04-22)
re: register variables in C wicklund@intellistor.com (1992-04-23)
| List of all articles for this month |

Newsgroups: comp.compilers
From: wicklund@intellistor.com (Tom Wicklund)
Keywords: C, optimize, registers
Organization: Compilers Central
References: 92-04-108
Date: Thu, 23 Apr 1992 18:23:25 GMT

>From experience using a number of PC compilers, I found that having the
compiler automatically place most used variables in registers resulted in
a larger gain in performance than most other optimizations. This involved
Turbo C, which has two simple optimizations -- remembering when a simple
variable is in a register and automatically enregistering two local
variables. Those two optimizations along with fairly good code generation
(e.g. fairly full use of the instruction set) resulted in performance
comparable to compilers which used register coloring, common subexpression
elimination, etc. but didn't automatically put variables in registers.
Turbo C's simple algorithm chose the correct 2 variables in almost every
case.


There are few cases where the programmer can do a better job than the
compiler, but most programmers add register keywords when initially
writing code and then don't update them as changes are made, so that the
manual decisions often become wrong with time.


It's probably best to let the compiler do the work and manually optimize
only in the code where performance really matters (since most programs
follow the general 80% of the time is spent in 20% of the code rule).
[The '86 series has such a small and irregular register set that I can
easily believe that graph coloring, which was designed for large and mostly
regular register sets, doesn't work well. -John]
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.