title: Avoid stalling pipeline by calculating conditional early
body: <p>When talking about the performance of ifs, we usually talk about how mispredictions can stall the pipeline. The recommended solutions I see are:</p>
  
  <ol>
  <li>Trust the branch predictor for conditions that usually have one result; or</li>
  <li>Avoid branching with a little bit of bit-magic if reasonably possible; or</li>
  <li>Conditional moves where possible.</li>
  </ol>
  
  <p>What I couldn't find was whether or not we can calculate the condition early to help where possible. So, instead of:</p>
  
  <pre><code>... work
  if (a &gt; b) {
      ... more work
  }
  </code></pre>
  
  <p>Do something like this:</p>
  
  <pre><code>bool aGreaterThanB = a &gt; b;
  ... work
  if (aGreaterThanB) {
      ... more work
  }
  </code></pre>
  
  <p>Could something like this potentially avoid stalls on this conditional altogether (depending on the length of the pipeline and the amount of work we can put between the bool and the if)? It doesn't have to be as I've written it, but <strong>is there a way to evaluate conditionals early so the CPU doesn't have to try and predict branches</strong>?</p>
  
  <p>Also, if that helps, is it something a compiler is likely to do anyway?</p>