title: When, if ever, is loop unrolling still useful?
body: <p>I've been trying to optimize some extremely performance-critical code (a quick sort algorithm that's being called millions and millions of times inside a monte carlo simulation) by loop unrolling.  Here's the inner loop I'm trying to speed up:</p>
  
  <pre><code>// Search for elements to swap.
  while(myArray[++index1] &lt; pivot) {}
  while(pivot &lt; myArray[--index2]) {}
  </code></pre>
  
  <p>I tried unrolling to something like:</p>
  
  <pre><code>while(true) {
      if(myArray[++index1] &lt; pivot) break;
      if(myArray[++index1] &lt; pivot) break;
      // More unrolling
  }
  
  
  while(true) {
      if(pivot &lt; myArray[--index2]) break;
      if(pivot &lt; myArray[--index2]) break;
      // More unrolling
  }
  </code></pre>
  
  <p>This made absolutely no difference so I changed it back to the more readable form.  I've had similar experiences other times I've tried loop unrolling.  Given the quality of branch predictors on modern hardware, when, if ever, is loop unrolling still a useful optimization?</p>