Abstractly considered, a program is a partly-specified computation: If it were completely specified, the compiler could compute the result immediately and return it, but typically a program uses some values which won't be known until the program is run -- values entered by the user, say.
Still, it is often the case that parts of the computation specified by the source text are constant expressions and can indeed be performed once while the is being compiled, instead of being performed every time the program is run.
Most compilers contain an optimizer subprogram intended to find certain kinds of constant expressions and replace them by their result.
Compiler optimization is a large, active and fascinating subfield of computer science in its own right, which each year produces more subtle data structures for representing code, and algorithms for transforming them: In essence, we are engaged in teaching the compiler to understand steadily more of the programs it compiles.
Good journals covering the subject include the ACM (Association for Computing Machinery)'s SIGPLAN (Special Interest Group for Programing LANguages) annual proceedings, and the ACM's journal TOPLAS (Transactions On Programing Languages And Systems.)
Go to the first, previous, next, last section, table of contents.