skip to main content
article
Open Access

Operator strength reduction

Published:01 September 2001Publication History
Skip Abstract Section

Abstract

Operator strength reduction is a technique that improves compiler-generated code by reformulating certain costly computations in terms of less expensive ones. A common case arises in array addressing expressions used in loops. The compiler can replace the sequence of multiplies generated by a direct translation of the address expression with an equivalent sequence of additions. When combined with linear function test replacement, strength reduction can speed up the execution of loops containing array references. The improvement comes from two sources: a reduction in the number of operations needed to implement the loop and the use of less costly operations.This paper presents a new algorithm for operator strength reduction, called OSR. OSR improves upon an earlier algorithm of Allen, Cocke, and Kennedy [Allen et al. 1981]. OSR operates on the static single assignment (SSA) form of a procedure [Cytron et al. 1991]. By taking advantage of the properties of SSA form, we have derived an algorithm that is simple to understand, quick to implement, and, in practice, fast to run. Its asymptotic complexity is, in the worst case, the same as the Allen, Cocke,and Kennedy algorithm (ACK). OSR achieves optimization results that are equivalent to those obtained with the ACK algorithm. OSR has been implemented in several research and production compilers.

References

  1. ALLEN, F. E. 1969. Program optimization. Annual Review in Automatic Programming 5, 239-308.Google ScholarGoogle Scholar
  2. ALLEN, F. E., COCKE,J.,AND KENNEDY, K. 1981. Reduction of operator strength. In Program Flow Analysis: Theory and Applications, S. S. Muchnick and N. D. Jones, Eds. Prentice-Hall, Englewood Cliffs, NJ, USA.Google ScholarGoogle Scholar
  3. ALPERN, B., WEGMAN,M.N.,AND ZADECK, F. K. 1988. Detecting equality of variables in programs. In Conference Record of the Fifteenth Annual ACM Symposium on Principles of Programming Languages. ACM, San Diego, California, 1-11. Google ScholarGoogle Scholar
  4. BERNSTEIN, R. 1986. Multiplication by integer constants. Software-Practice and Experience 16,7 (July), 641-652. Google ScholarGoogle Scholar
  5. BODIK, R., GUPTA, R., AND SOFFA, M. L. 1998. Complete removal of redundant computations. SIGPLAN Notices 33, 5 (May), 1-14. Proceedings of the ACM SIGPLAN '98 Conference on Programming Language Design and Implementation. Google ScholarGoogle Scholar
  6. BRIGGS,P.AND COOPER, K. D. 1994. Effective partial redundancy elimination. SIGPLAN Notices 29, 6 (June), 159-170. Google ScholarGoogle Scholar
  7. BRIGGS, P., COOPER,K.D.,HARVEY,T.J.,AND SIMPSON, L. T. 1998. Practical improvements to the construction and destruction of static single assignment form. Software-Practice and Experience 28, 8 (July), 859-881. Google ScholarGoogle Scholar
  8. BRIGGS, P., COOPER,K.D.,AND SIMPSON, L. T. 1997. Value numbering. Software-Practice and Experience 27, 6, 710-724. Google ScholarGoogle Scholar
  9. BRIGGS, P., COOPER,K.D.,AND TORCZON, L. 1994. Improvements to graph coloring register allocation. ACM Trans. Program. Lang. Syst. 16, 3 (May), 428-455. Google ScholarGoogle Scholar
  10. BRIGGS,P.AND HARVEY, T. J. 1994. Multiplication by integer constants. This is a "web", a literate programming document. See http://softlib.rice.edu/MSCP.Google ScholarGoogle Scholar
  11. CAI,J.AND PAIGE, R. 1991. "Look Ma, no hashing, and no arrays neither". In Conference Record of the Eighteenth Annual ACM Symposium on Principles of Programming Languages. ACM, Orlando, Florida, 143-154. Google ScholarGoogle Scholar
  12. CHAITIN,G.J.,AUSLANDER, M. A., CHANDRA, A. K., COCKE, J., HOPKINS,M.E.,AND MARKSTEIN,P.W. 1981. Register allocation via coloring. Computer Languages 6, 47-57.Google ScholarGoogle Scholar
  13. CHASE, D. R. 1988. Personal communication in the form of an unpublished report.Google ScholarGoogle Scholar
  14. CHOI, J.-D., CYTRON, R., AND FERRANTE, J. 1991. Automatic construction of sparse data flow evaluation graphs. In Conference Record of the Eighteenth Annual ACM Symposium on Principles of Programming Languages. ACM, Orlando, Florida, 55-66. Google ScholarGoogle Scholar
  15. CLICK,C.AND COOPER, K. D. 1995. Combining analyses, combining optimizations. ACM Trans. Program. Lang. Syst. 17, 2 (Mar.), 181-196. Google ScholarGoogle Scholar
  16. COCKE,J.AND KENNEDY, K. 1977. An algorithm for reduction of operator strength. Communications of the ACM 20, 11 (Nov.), 850-856. Google ScholarGoogle Scholar
  17. COCKE,J.AND MARKSTEIN, P. 1980a. Measurement of program improvement algorithms. In Proceedings of Information Processing 80. North Holland Publishing Company, Tokyo, Japan.Google ScholarGoogle Scholar
  18. COCKE,J.AND MARKSTEIN, P. 1980b. Strength reduction for division and modulo with application to a multilevel store. IBM J. Res. Dev. 24, 6, 692-694.Google ScholarGoogle Scholar
  19. COCKE,J.AND SCHWARTZ, J. T. 1970. Programming languages and their compilers: Preliminary notes. Tech. rep., Courant Institute of Mathematical Sciences, New York University.Google ScholarGoogle Scholar
  20. COOPER,K.D.AND SIMPSON, L. T. 1995. SCC-based value numbering. Tech. Rep. TR95636, Center for Research on Parallel Computation, Rice University. Oct.Google ScholarGoogle Scholar
  21. CYTRON, R., FERRANTE, J., ROSEN, B. K., WEGMAN,M.N.,AND ZADECK, F. K. 1991. Efficiently computing static single assignment form and the control dependence graph. ACM Trans. Program. Lang. Syst. 13, 4 (Oct.), 451-490. Google ScholarGoogle Scholar
  22. DHAMDHERE, D. M. 1979. On algorithms for operator strength reduction. Communications of the ACM 22, 5 (May), 311-312.Google ScholarGoogle Scholar
  23. DHAMDHERE, D. M. 1989. A new algorithm for composite hoisting and strength reduction. Int. J. Comput. Math. 27, 1, 1-14.Google ScholarGoogle Scholar
  24. DRECHSLER, K.-H. AND STADEL, M. P. 1993. A variation of Knoop, Ruthing, and Steffen's "lazy code motion". SIGPLAN Notices 28, 5 (May), 29-38. Google ScholarGoogle Scholar
  25. EARLY, J. 1974. High level iterators and a method of automatically designing data structure representation. Tech. Rep. ERL-M416, Computer Science Division, University of California, Berkeley. Feb.Google ScholarGoogle Scholar
  26. FONG, A. C. 1979. Automatic improvement of programs in very high level languages. In Conference Record of the Sixth Annual ACM Symposium on Principles of Programming Languages. ACM, San Antonio, Texas, 21-28. Google ScholarGoogle Scholar
  27. FONG,A.C.AND ULLMAN, J. D. 1976. Induction variables in very high level languages. In Conference Record of the Third ACM Symposium on Principles of Programming Languages. ACM, Atlanta, Georgia, 104-112. Google ScholarGoogle Scholar
  28. GRANLUND, T. 1995. Private communication with P. Briggs. Discussion of his work in building the routine synth mult for the Gnu C Compiler.Google ScholarGoogle Scholar
  29. GRANLUND,T.AND MONTGOMERY, P. L. 1994. Division by invariant integers using multiplication. SIGPLAN Notices 29, 6 (June), 61-72. Google ScholarGoogle Scholar
  30. GUPTA, R., BERSON,D.A.,AND FANG, J. Z. 1998. Path profile guided partial redundancy elimination using speculation. In Proceedings of the IEEE 1998 International Conference on Computer Languages. IEEE Computer Society, Chicago, IL., USA, 230-239. Google ScholarGoogle Scholar
  31. HAVLAK, P. 1997. Nesting of reducible and irreducible loops. ACM Trans. Program. Lang. Syst. 19, 4 (July), 557-567. Google ScholarGoogle Scholar
  32. ISSAC,J.AND DHAMDHERE, D. M. 1980. A composite algorithm for strength reduction and code movement. Int. J. Comput. Info. Sci. 9, 3, 243-273.Google ScholarGoogle Scholar
  33. KAM,J.B.AND ULLMAN, J. D. 1976. Global data flow analysis and iterative algorithms. J. ACM 23, 1 (Jan.), 158-171. Google ScholarGoogle Scholar
  34. KENNEDY, K. 1973. Reduction in strength using hashed temporaries. SETL Newsletter 102, Courant Institute of Mathematical Sciences, New York University. Mar.Google ScholarGoogle Scholar
  35. KENNEDY, K. 1978. Use-definition chains with applications. Computer Languages 3, 163- 179.Google ScholarGoogle Scholar
  36. KNOOP, J., RUTHING,O.,AND STEFFEN, B. 1992. Lazy code motion. SIGPLAN Notices 27, 7 (July), 224-234. Google ScholarGoogle Scholar
  37. KNOOP, J., RUTHING,O.,AND STEFFEN, B. 1993. Lazy strength reduction. J. Program. Lang. 1,1, 71-91.Google ScholarGoogle Scholar
  38. KNOOP, J., RUTHING,O.,AND STEFFEN, B. 1994. Optimal code motion: Theory and practice. ACM Trans. Program. Lang. Syst. 16, 4 (July), 1117-1155. Google ScholarGoogle Scholar
  39. LENGAUER,T.AND TARJAN, R. E. 1979. A fast algorithm for finding dominators in a flowgraph. ACM Trans. Program. Lang. Syst. 1, 1 (July), 121-141. Google ScholarGoogle Scholar
  40. LIU,Y.A.AND STOLLER, S. D. 1998. Loop optimization for aggregate array computations. In IEEE 1998 International Conference on Computer Languages. IEEE CS Press, Los Alamitos, CA, 262- 271. Google ScholarGoogle Scholar
  41. MARKSTEIN,P.W.,MARKSTEIN,V.,AND ZADECK, F. K. 1994. Reassociation and strength reduction. Chapter from an unpublished book, Optimization in Compilers.Google ScholarGoogle Scholar
  42. MOREL,E.AND RENVOISE, C. 1979. Global optimization by suppression of partial redundancies. Communications of the ACM 22, 2 (Feb.), 96-103. Google ScholarGoogle Scholar
  43. PAIGE,R.AND KOENIG, S. 1982. Finite differencing of computable expressions. ACM Trans. Program. Lang. Syst. 4, 3 (July), 402-454. Google ScholarGoogle Scholar
  44. PAIGE,R.AND SCHWARTZ, J. T. 1977. Reduction in strength of high level operations. In Conference Record of the Fourth ACM Symposium on Principles of Programming Languages. ACM, Los Angeles, California, 58-71. Google ScholarGoogle Scholar
  45. SANTHANAM, V. 1992. Register reassociation in PA-RISC compilers. Hewlett-Packard Journal 14,6 (June), 33-38.Google ScholarGoogle Scholar
  46. SCARBOROUGH,R.G.AND KOLSKY, H. G. 1980. Improved optimization of FORTRAN object programs. IBM J. Res. Dev. 24, 6 (Nov.), 660-676.Google ScholarGoogle Scholar
  47. SITES, R. L. 1979. The compilation of loop induction expressions. ACM Trans. Program. Lang. Syst. 1, 1 (July), 50-57. Google ScholarGoogle Scholar
  48. TARJAN, R. E. 1972. Depth first search and linear graph algorithms. SIAM J. Comput. 1, 2 (June), 146-160.Google ScholarGoogle Scholar
  49. TARJAN, R. E. 1974. Testing flow graph reducibility. J. Comput. Syst. Sci. 9, 355-365.Google ScholarGoogle Scholar
  50. VICK, C. A. 1994. SSA based reduction of operator strength. M.S. dissertation, Rice University, Department of Computer Science.Google ScholarGoogle Scholar
  51. WEGMAN,M.N.AND ZADECK, F. K. 1991. Constant propagation with conditional branches. ACM Trans. Program. Lang. Syst. 13, 2 (Apr.), 211-236. Google ScholarGoogle Scholar
  52. WOLFE, M. 1992. Beyond induction variables. SIGPLAN Notices 27, 7 (July), 162-174. Google ScholarGoogle Scholar
  53. WU, Y. 1995. Strength reduction of multiplications by integer constants. SIGPLAN Notices 32,2 (Feb.), 42-48. Google ScholarGoogle Scholar

Index Terms

  1. Operator strength reduction

    Recommendations

    Comments

    Login options

    Check if you have access through your login credentials or your institution to get full access on this article.

    Sign in

    Full Access

    • Published in

      cover image ACM Transactions on Programming Languages and Systems
      ACM Transactions on Programming Languages and Systems  Volume 23, Issue 5
      September 2001
      81 pages
      ISSN:0164-0925
      EISSN:1558-4593
      DOI:10.1145/504709
      Issue’s Table of Contents

      Copyright © 2001 ACM

      Publisher

      Association for Computing Machinery

      New York, NY, United States

      Publication History

      • Published: 1 September 2001
      Published in toplas Volume 23, Issue 5

      Permissions

      Request permissions about this article.

      Request Permissions

      Check for updates

      Qualifiers

      • article

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader