Simple code optimizations

Program optimization has received a great deal of attention for many years, which has resulted in numerous advances in compiler technology. The effectiveness of various simple optimizations has received comparably little attention during the same time period. The simplicity of most programs suggests that straightforward optimizations pay the greatest dividends. This paper describes three such optimizations suitable for one‐pass compilers. The optimizations involve expression rearrangement, instruction selection, and the use of a cache for the allocation of resources. The cost of these optimizations is low; none require major changes to the size or structure of the compiler or reduce compilation speed by more than 10%. The benefits are high; each optimization results in at least a 10% average reduction in object code size and a corresponding reduction in execution time. Examples and implementation details are also described.

[1]  Urs Ammann On code generation in a PASCAL compiler , 1981, Pascal - The Language and its Implementation.

[2]  Jon Louis Bentley,et al.  Writing efficient programs , 1982 .

[3]  Susan L. Graham,et al.  An experiment in table driven code generation , 1982, SIGPLAN '82.

[4]  Charles N. Fischer,et al.  Description-driven code generation using attribute grammars , 1982, POPL '82.

[5]  Neil D. Jones,et al.  Program Flow Analysis: Theory and Application , 1981 .

[6]  Jon Louis Bentley Programming pearls: data structures programs , 1983, CACM.

[7]  David Alex Lamb Construction of a peephole optimizer , 1981, Softw. Pract. Exp..

[8]  David R. Hanson,et al.  The Y programming language , 1981, SIGP.

[9]  Insup Lee,et al.  A contextual analysis of Pascal programs , 1982, Softw. Pract. Exp..

[10]  Niklaus Wirth,et al.  Algorithms + Data Structures = Programs , 1976 .

[11]  David R. Hanson Code Improvement Via Lazy Evaluation , 1980, Inf. Process. Lett..

[12]  Susan L. Graham,et al.  A new method for compiler code generation , 1978, POPL '78.

[13]  Andrew S. Tanenbaum,et al.  Implications of structured programming for machine architecture , 1978, CACM.

[14]  Donald E. Knuth,et al.  An empirical study of FORTRAN programs , 1971, Softw. Pract. Exp..

[15]  Ravi Sethi,et al.  Control Flow Aspects of Semantics-Directed Compiling , 1983, TOPL.

[16]  Jacques J. Arsac,et al.  Syntactic source to source transforms and program manipulation , 1979, CACM.

[17]  Forest Baskett,et al.  The best simple code generation technique for WHILE, FOR, and DO loops , 1978, SIGP.

[18]  Peter Henderson,et al.  A lazy evaluator , 1976, POPL.

[19]  John Banning,et al.  : An Efficient , 2022 .

[20]  William E. Weihl,et al.  Interprocedural data flow analysis in the presence of pointers, procedure variables, and label variables , 1980, POPL '80.

[21]  William A. Wulf,et al.  The Design of an Optimizing Compiler , 1975 .

[22]  Prateek Mishra,et al.  Compiling short‐circuit boolean expressions in one pass , 1981, Softw. Pract. Exp..

[23]  Brian W. Kernighan,et al.  RATFOR—a preprocessor for a rational fortran , 1975, Softw. Pract. Exp..

[24]  Christopher W. Fraser,et al.  The Design and Application of a Retargetable Peephole Optimizer , 1980, TOPL.

[25]  Richard L. Sites,et al.  Programming tools: statement counts and procedure timings , 1978, SIGP.