Strength Reduction of Integer Division and Modulo Operations

  • Jeffrey Sheldon
  • Walter Lee
  • Ben Greenwald
  • Saman Amarasinghe
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 2624)


Integer division, modulo, and remainder operations are expressive and useful operations. They are logical candidates to express complex data accesses such as the wrap-around behavior in queues using ring buffers. In addition, they appear frequently in address computations as a result of compiler optimizations that improve data locality, perform data distribution, or enable parallelization. Experienced application programmers, however, avoid them because they are slow. Furthermore, while advances in both hardware and software have improved the performance of many parts of a program, few are applicable to division and modulo operations. This trend makes these operations increasingly detrimental to program performance.

This paper describes a suite of optimizations for eliminating division, modulo, and remainder operations from programs. These techniques are analogous to strength reduction techniques used for multiplications. In addition to some algebraic simplifications, we present a set of optimization techniques that eliminates division and modulo operations that are functions of loop induction variables and loop constants. The optimizations rely on algebra, integer programming, and loop transformations.


Strength Reduction Iteration Space Division Operation Address Computation Loop Transformation 
These keywords were added by machine and not by the authors. This process is experimental and the keywords may be updated as the learning algorithm improves.


Unable to display preview. Download preview PDF.

Unable to display preview. Download preview PDF.


  1. [1]
    R. Alverson. Integer Division Using Reciprocals. In Proceedings of the Tenth Symposium on Computer Arithmetic, Grenoble, France, June 1991.Google Scholar
  2. [2]
    S. Amarasinghe. Parallelizing Compiler Techniques Based on Linear Inequalities. In Ph.D Thesis, Stanford University. Also appears as Techical Report CSL-TR-97-714, Jan 1997.Google Scholar
  3. [3]
    C. Ancourt and F. Irigoin. Scanning Polyhedra with Do Loops. In Proceedings of the Third ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming, pages 39–50, Williamsburg, VA, Apr. 1991.Google Scholar
  4. [4]
    M. Ancourt. Génération Automatique de Codes de Transfert pour Multiprocesseurs à Mémoires Locales. PhD thesis, Université Paris VI, Mar. 1991.Google Scholar
  5. [5]
    J. M. Anderson, S. P. Amarasinghe, and M. S. Lam. Data and Computation Transformations for Multiprocessors. In Proceedings of the Fifth ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming, pages 166–178, Santa Barbara, CA, July 1995.Google Scholar
  6. [6]
    R. Barua, W. Lee, S. Amarasinghe, and A. Agarwal. Maps: A Compiler-Managed Memory System for Raw Machines. In Proceedings of the 26th International Symposium on Computer Architecture, Atlanta, GA, May 1999.Google Scholar
  7. [7]
    J. Cocke and P. Markstein. Strength Reduction for Division and Modulo with Application to Accessing a Multilevel Store. IBM Journal of Research and Development, 24(6):692–694, November 1980.CrossRefGoogle Scholar
  8. [8]
    G. Dantzig. Linear Programming and Extensions. Princeton University Press, Princeton, NJ, 1963.zbMATHGoogle Scholar
  9. [9]
    G. Dantzig and B. Eaves. Fourier-Motzkin Elimination and its Dual. Journal of Combinatorial Theory (A), 14:288–297, 1973.zbMATHCrossRefMathSciNetGoogle Scholar
  10. [10]
    R. Duffin. On Fourier’s Analysis of Linear Inequality Systems. In Mathematical Programming Study 1, pages 71–95. North-Holland, 1974.MathSciNetGoogle Scholar
  11. [11]
    R. L. Graham, D. E. Knuth, and O. Patashnik. Concrete Mathematics. Addison-Wesley, Reading, MA, 1989.zbMATHGoogle Scholar
  12. [12]
    T. Granlund and P. Montgomery. Division by Invariant Integers using Multiplication. In Proceedings of the SIGPLAN’ 94 Conference on Programming Language Design and Implementation, Orlando, FL, June 1994.Google Scholar
  13. [13]
    B. Greenwald. A Technique for Compilation to Exposed Memory Hierarchy. Master’s thesis, Massachusetts Institute of Technology, Department of Electrical Engineering and Computer Science, September 1999.Google Scholar
  14. [14]
    D. Magenheimer, L. Peters, K. Peters, and D. Zuras. Integer Multiplication and Division On the HP Precision Architecture. IEEE Transactions on Computers, 37:980–990, Aug. 1988.CrossRefGoogle Scholar
  15. [15]
    C. A. Moritz, M. Frank, W. Lee, and S. Amarasinghe. Hot Pages: Software Caching for Raw Microprocessors. Technical Memo LCS-TM-599, Laboratory for Computer Science, Massachusetts Institute of Technology, Sept 1999.Google Scholar
  16. [16]
    S. Oberman. Design Issues in High Performance Floating Point Arithmetic Units. PhD thesis, Stanford University, December 1996.Google Scholar
  17. [17]
    W. Pugh. The Omega test: A fast and practical integer programming algorithm for dependence analysis. In Proceedings of Supercomputing’ 91, Albuquerque, NM, Nov. 1991.Google Scholar
  18. [18]
    A. Schrijver. Theory of Linear and Integer Programming. John Wiley and Sons, Chichester, Great Britain, 1986.zbMATHGoogle Scholar
  19. [19]
    M. B. Taylor. Design Decisions in the Implementation of a Raw Architecture Workstation. Master’s thesis, Massachusetts Institute of Technology, Department of Electrical Engineering and Computer Science, September 1999.Google Scholar
  20. [20]
    H. Williams. Fourier-Motzkin Elimination Extension to Integer Programming Problems. Journal of Combinatorial Theory, 21:118–123, 1976.zbMATHCrossRefGoogle Scholar
  21. [21]
    R. Wilson, R. French, C. Wilson, S. Amarasinghe, J. Anderson, S. Tjiang, S.-W. Liao, C.-W. Tseng, M. Hall, M. Lam, and J. Hennessy. SUIF: An Infrastructure for Research on Parallelizing and Optimizing Compilers. ACM SIGPLAN Notices, 29(12), Dec. 1996.Google Scholar
  22. [22]
    M. E. Wolf. Improving Locality and Parallelism in Nested Loops. PhD thesis, Dept. of Computer Science, Stanford University, Aug. 1992.Google Scholar

Copyright information

© Springer-Verlag Berlin Heidelberg 2003

Authors and Affiliations

  • Jeffrey Sheldon
    • 1
  • Walter Lee
    • 1
  • Ben Greenwald
    • 1
  • Saman Amarasinghe
    • 1
  1. 1.M.I.T. Laboratory for Computer ScienceUSA

Personalised recommendations