title: Why does GCC not auto-vectorize this loop?
body: <p>I am attempting to optimize a loop that accounts for a lot of my program's computation time.</p>
  
  <p>But when I turn on auto-vectorization with -O3 -ffast-math -ftree-vectorizer-verbose=6 GCC outputs that it can not vectorize the loop.</p>
  
  <p>I am using GCC 4.4.5</p>
  
  <p>The code:</p>
  
  <pre><code>/// Find the point in the path with the largest v parameter
  void prediction::find_knife_edge(
      const float * __restrict__ const elevation_path,
      float * __restrict__ const diff_path,
      const float path_res,
      const unsigned a,
      const unsigned b,
      const float h_a,
      const float h_b,
      const float f,
      const float r_e,
  ) const
  {
      float wavelength = (speed_of_light * 1e-6f) / f;
  
      float d_ab = path_res * static_cast&lt;float&gt;(b - a);
  
      for (unsigned n = a + 1; n &lt;= b - 1; n++)
      {
          float d_an = path_res * static_cast&lt;float&gt;(n - a);
          float d_nb = path_res * static_cast&lt;float&gt;(b - n);
  
          float h = elevation_path[n] + (d_an * d_nb) / (2.0f * r_e) - (h_a * d_nb + h_b * d_an) / d_ab;
          float v = h * std::sqrt((2.0f * d_ab) / (wavelength * d_an * d_nb));
  
          diff_path[n] = v;
      }
  }
  </code></pre>
  
  <p>The messages from GCC:</p>
  
  <pre><code>note: not vectorized: number of iterations cannot be computed.
  note: not vectorized: unhandled data-ref 
  </code></pre>
  
  <p>On the page about auto-vectorization ( <a href="http://gcc.gnu.org/projects/tree-ssa/vectorization.html">http://gcc.gnu.org/projects/tree-ssa/vectorization.html</a> ) it states that it supports unknown loop bounds.</p>
  
  <p>If I replace the for with</p>
  
  <pre><code>for (unsigned n = 0; n &lt;= 100; n++)
  </code></pre>
  
  <p>then it vectorizes it.</p>
  
  <p>What am I doing wrong?</p>
  
  <p>The lack of detailed documentation on exactly what these messages mean and the ins/outs of GCC auto-vectorization is rather annoying.</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Thanks to David I changed the loop to this:</p>
  
  <pre><code> for (unsigned n = a + 1; n &lt; b; n++)
  </code></pre>
  
  <p>Now GCC attempts to vectorize the loop but throws out this error:</p>
  
  <pre><code> note: not vectorized: unhandled data-ref
   note: Alignment of access forced using peeling.
   note: Vectorizing an unaligned access.
   note: vect_model_induction_cost: inside_cost = 1, outside_cost = 2 .
   note: not vectorized: relevant stmt not supported: D.76777_65 = (float) n_34;
  </code></pre>
  
  <p>What does "D.76777_65 = (float) n_34;" mean?</p>