The fundamental questions

There are two questions that you need to ask when compiling your program:

1. What do I know about the platforms that this program will run on?
2. What do I know about the assumptions that are made in the code?

The answers to these two questions determine what compiler options you should use.

The target platform

What platforms do you expect your code to run on? The choice of platform determines:

1. 32-bit or 64-bit instruction set
2. Instruction set extensions the compiler can use
3. Instruction scheduling depending on instruction execution times
4. Cache configuration

The first three are often the most important ones.

Read the full article here; strongly recommended.