Loop Quasi-Invariant Chunk Detection

  • Jean-Yves Moyen
  • Thomas Rubiano
  • Thomas Seiller
Conference paper
Part of the Lecture Notes in Computer Science book series (LNCS, volume 10482)


Several techniques for analysis and transformations are used in compilers. Among them, the peeling of loops for hoisting quasi-invariants can be used to optimize generated code, or simply ease developers’ lives. In this paper, we introduce a new concept of dependency analysis borrowed from the field of Implicit Computational Complexity (ICC), allowing to work with composed statements called “Chunks” to detect more quasi-invariants. Based on an optimization idea given on a WHILE language, we provide a transformation method - reusing ICC concepts and techniques [8, 10] - to compilers. This new analysis computes an invariance degree for each statement or chunks of statements by building a new kind of dependency graph, finds the “maximum” or “worst” dependency graph for loops, and recognizes if an entire block is Quasi-Invariant or not. This block could be an inner loop, and in that case the computational complexity of the overall program can be decreased.

In this paper, we introduce the theory around this concept and present a prototype analysis pass implemented on LLVM. We already implemented a proof of concept on a toy C parser ( analysing and transforming the AST representation. In a very near future, we will implement the corresponding transformation within our prototype LLVM pass and provide benchmarks comparisons.


Static analysis Transformations Optimization Compilers Loop invariants Complexity Quasi-invariants 


  1. 1.
    Abel, A., Altenkirch, T.: A predicative analysis of structural recursion. J. Funct. Program. 12(1), 1–41 (2002)MathSciNetCrossRefzbMATHGoogle Scholar
  2. 2.
    Baillot, P., Terui, K.: Light types for polynomial time computation in lambda calculus. Inf. Comput. 201(1), 41–62 (2009)MathSciNetCrossRefzbMATHGoogle Scholar
  3. 3.
    Bellantoni, S., Cook, S.: A new recursion-theoretic characterization of the poly-time functions. Comput. Complex. 2, 97–110 (1992)CrossRefzbMATHGoogle Scholar
  4. 4.
    Cobham, A.: The intrinsic computational difficulty of functions. In: Bar-Hillel, Y. (ed.) CLMPS (1962)Google Scholar
  5. 5.
    Cocke, J.: Global common subexpression elimination. SIGPLAN Not. 5(7), 20–24 (1970)CrossRefGoogle Scholar
  6. 6.
    Girard, J.-Y.: Linear logic. Theor. Comput. Sci. 50, 1–110 (1987)MathSciNetCrossRefzbMATHGoogle Scholar
  7. 7.
    Hofmann, M.: Linear types and non-size increasing polynomial time computation. In: LICS, pp. 464–473 (1999)Google Scholar
  8. 8.
    Kristiansen, L.: Notes on code motion. Private communicationGoogle Scholar
  9. 9.
    Kristiansen, L., Jones, N.D.: The flow of data and the complexity of algorithms. Trans. Comput. Log. 10(3), 28 (2009)zbMATHGoogle Scholar
  10. 10.
    Kuck, D.J., Kuhn, R.H., Padua, D.A., Leasure, B., Wolfe, M.: Dependence graphs and compiler optimizations. In: POPL (1981)Google Scholar
  11. 11.
    Laird, J., McCusker, G., Manzonetto, G., Pagani, M.: Weighted relational models of typed lambda-calculi. In: IEEE/ACM LICS (2013)Google Scholar
  12. 12.
    Lee, C.S., Jones, N.D., Ben-Amram, A.M.: The size-change principle for program termination. In: POPL (2001)Google Scholar
  13. 13.
    Moyen, J.-Y.: Resource control graphs. ACM Trans. Comput. Log. 10, 29 (2009)MathSciNetCrossRefzbMATHGoogle Scholar
  14. 14.
    Seiller, T.: Interaction graphs: additives. Ann. Pure Appl. Log. 167, 95–154 (2016)MathSciNetCrossRefzbMATHGoogle Scholar
  15. 15.
    Seiller, T.: Interaction graphs: full linear logic. In: IEEE/ACM LICS (2016)Google Scholar
  16. 16.
    Song, L., Futamura, Y., Glück, R., Hu, Z.: A loop optimization technique based on quasi-invariance (2000)Google Scholar

Copyright information

© Springer International Publishing AG 2017

Authors and Affiliations

  1. 1.Department of Computer ScienceUniversity of Copenhagen (DIKU)CopenhagenDenmark
  2. 2.LIPNUniversité Paris 13ParisFrance

Personalised recommendations