title: gcc differences between -O3 vs -Ofast optimizations
body: <p>I was just reading through the gcc manual to find out the difference between <code>-O3</code> and <code>-Ofast</code>.</p>
  <p>For <code>-O3</code></p>
  <blockquote>
  <p>-O3</p>
  <pre><code>Optimize yet more. -O3 turns on all optimizations specified by -O2 and also turns on the following optimization flags:
  
  -fgcse-after-reload 
  -fipa-cp-clone
  -floop-interchange 
  -floop-unroll-and-jam 
  -fpeel-loops 
  -fpredictive-commoning 
  -fsplit-paths 
  -ftree-loop-distribute-patterns 
  -ftree-loop-distribution 
  -ftree-loop-vectorize 
  -ftree-partial-pre 
  -ftree-slp-vectorize 
  -funswitch-loops 
  -fvect-cost-model 
  -fversion-loops-for-strides
  </code></pre>
  </blockquote>
  <p>While of <code>-Ofast</code></p>
  <blockquote>
  <p>-Ofast</p>
  <pre><code>Disregard strict standards compliance. -Ofast enables all -O3 optimizations. It also enables optimizations that are not valid for
  all standard-compliant programs. It turns on -ffast-math,
  -fallow-store-data-races and the Fortran-specific -fstack-arrays, unless -fmax-stack-var-size is specified, and -fno-protect-parens
  </code></pre>
  </blockquote>
  <p>Therefore I was wondering, if maybe <code>-Ofast</code> is for some reason less safe than <code>-O3</code>, and therefore I should stick to <code>-O3</code> most of the times then.</p>
  <p>Can you clarify the &quot;practical difference&quot; when using them? And if <code>-Ofast</code> is actually safe?</p>