Clever Geek Handbook
📜 ⬆️ ⬇️

Convolution of constants

The folding of constants ( constant folding ) and the propagation of constants (also promoting constants , duplicating constants , constant propagation ) are often used in modern optimization compilers to reduce redundant calculations by replacing constant expressions and variables with their values [1] . An extended sparse conditional constant propagation algorithm is also often used, which simultaneously distributes constants and removes some dead code [2] .

Content

  • 1 Convolution of constants
  • 2 Propagation of constants
  • 3 See also
  • 4 notes
  • 5 Literature
  • 6 References

Convolution of constants

Convolution of constants is an optimization that calculates constant expressions at the compilation stage. First of all, constant expressions containing numerical literals are simplified . Expressions containing never-changing variables or variables declared as constants can also be simplified. Consider an example:

  i = 320 * 200 * 32 ;

A compiler that supports convolution of constants will not generate two multiplication instructions and record the result. Instead, it recognizes this construct as a constant expression and replaces it with the calculated value (in this case 2,048,000).

Constant Propagation

The propagation of constants is optimization , replacing an expression that always returns the same constant when executed, by this constant itself [3] . This can be a constant defined earlier, or a built-in function applied to constants. Consider the following example:

  int x = 14 ;
   int y = 7 - x / 2 ;
   return y * ( 28 / x + 2 );

Spread x returns:

  int x = 14 ;
   int y = 7 - 14/2 ;
   return y * ( 28/14 + 2 );

Further, the folding of constants and the distribution of y return the following (assignments x and y are likely to be removed in the future by optimizing the removal of dead code ):

  int x = 14 ;
   int y = 0 ;
   return 0 ;

See also

  • Control flow graph
  • SSA view

Notes

  1. ↑ Workshop "Optimizing Compilers" (for example, GCC). - NSU them. Lobachevsky. - S. 100.
  2. ↑ Muchnick, 1997 , p. 362-370.
  3. ↑ Dragon Book, 2008 , p. 760.

Literature

  • Steven S. Muchnick. Advanced Compiler Design and Implementation. - 5th edition. - San Francisco: Morgan Kaufmann Publishers , 1997 .-- 856 p. - ISBN 1-55860-320-4 .
  • Alfred Aho, Monica Lam, Ravi Seti, Jeffrey Ullman. Compilers: principles, technologies and tools = Compilers: Principles, Techniques, and Tools. - 2nd edition. - M .: "Williams", 2008. - 1184 p. - 1,500 copies - ISBN 978-5-8459-1349-4 .

Links

  • Advanced constant propagation algorithm using GSA representation
  • Optimizations in compilers. Part 1
Source - https://ru.wikipedia.org/w/index.php?title=Convert_constant&oldid=88947530


More articles:

  • Kolzakov, Konstantin Yakovlevich
  • Magnesium Dihydroorthophosphate
  • Priozerskoye
  • Palazzo dei Kamerlingi
  • Great White Egret
  • Vadim Getman Street (Kiev)
  • Tepe Yahya
  • Shmarinov, Alexey Alekseevich
  • List of the largest metropolitan metropolitan areas in terms of passenger traffic
  • Flegon, Alec

All articles

Clever Geek | 2019