Dear GCC Developers, I would like to learn more how GCC implements algebraic optimization heuristic such as given in -ffast-math . In particular, I have a type Number that is used in a code initial_source.cpp that upon compilation and execution writes a second file generated_code.cpp . Basically, each operator of Number writes a bit of text into the file generated_code.cpp . The generated_code.cpp is a text file is created at run-time. Hence it is invariant to compiler optimizations. Different levels of manual (human-made) algebraic expression optimizations in initial_source.cpp will vastly improve brevity and performance of generated_code.cpp . It does not matter what Number implements (it literally just writes files) or what the generated_code.cpp is. This is because compiler optimizations generated_code.cpp are ultimately heuristics and hence cannot replace optimization heuristics on the algebraic expressions of initial_source.cpp . Since GCC can optimize algebraic expressions involving double, float, etc., I would enjoy if I could use it (somehow) to improve algebraic expressions of my initial_source.cpp before compilation. Algebraic expressions are more optimal when they would run faster on double and if any constants are lumped and precomputed. Notice that for a custom object x and the assignment z=1+x+2+3+4+5 such precomputations will not take place when the compiler sees x only as a class that writes strings. Furthermore, such algebraic optimizations alter the result of execution of initial_source.cpp from (e.g.) "z=1+x+2+3+4+5" to "z=15+x". But this is exactly what I seek. Things get too complicated when intermediate results and sign-resolutions throughout a scope may be algebraically optimizable. Questions: 1) Is there maybe a virtual type from which my Number can inherit, so as to enable algebraic expression optimizations? 2) Or is there maybe an option that could be added to the compilation command where I add the name of my type? 3*) Is it realistic or possible at all to implement these sorts of heuristic only by virtue of expression templates? I doubt that because to me it seems one would have to repeatedly iterate over a DAG and add and remove nodes to/from it. Templates could only do finitely many passes and global DAG transformations seem ambitious when limited to template-meta-programming. Thank you very much for any ideas of help!