Outsmarting The Compiler

Outsmarting the compiler refers to any attempt to defeat the optimization heuristics (or other techniques for code improvement) of a compiler, often with the hubris that expert programmers can do better at code generation than modern optimizing compilers. (While this may be true, most expert programmers know better to outsmart the compiler except in specific circumstances; conversely most programmers who spend lots of time trying to outsmart compilers aren't experts, and often make things worse.)

Unless profiling tells you that your compiler is doing the wrong thing, and this is leading the code to not meet its performance requirements, doing so is PrematureOptimization, and as such is an AntiPattern.

OutsmartingTheCompiler is frequently bad because:

On the other hand, it is occasionally useful because:

Examples of outsmarting the compiler:


View edit of February 6, 2007 or FindPage with title or text search