title: g++: optimization -march=haswell and newer changes numerical result
body: <p>I have been working on optimizing performance and of course doing regression tests when I noticed that g++ seems to alter results depending on chosen optimization. So far I thought that <code>-O2 -march=[whatever]</code> should yield the exact same results for numerical computations regardless of what architecture is chosen. However this seems not to be the case for g++. While using old architectures up to ivybridge yields the same results as clang does for any architecture, I get different results for gcc for haswell and newer. Is this a bug in gcc or did I misunderstand something about optimizations? I am really startled because clang does not seem to show this behavior.</p>
  
  <p>Note that I am well aware that the differences are within machine precision, but they still disturb my simple regression checks.</p>
  
  <p>Here is some example code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;armadillo&gt;
  
  int main(){
      arma::arma_rng::set_seed(3);
      arma::sp_cx_mat A = arma::sprandn&lt;arma::sp_cx_mat&gt;(20,20, 0.1);
      arma::sp_cx_mat B = A + A.t();
      arma::cx_vec eig;
      arma::eigs_gen(eig, B, 1, "lm", 0.001);
      std::cout &lt;&lt; "eigenvalue: " &lt;&lt; eig &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>Compiled using:</p>
  
  <pre><code>g++ -march=[architecture] -std=c++14 -O2 -o test example.cpp -larmadillo
  </code></pre>
  
  <p>gcc version: 6.2.1</p>
  
  <p>clang version: 3.8.0</p>
  
  <p>Compiled for 64 bit, executed on an Intel Skylake processor.</p>