title: is checking a complex expression in a loop optimized by the compiler?
body: <p>(If this is a duplicate please point me to an answer)</p>
  
  <p>I have two scenarios where a loop is checking a complex expression over and over again (a complex expression would consist of math operations and retrieving data):</p>
  
  <pre><code>for (int i = 0; i &lt; expression; i++) {
      // stuff
  }
  
  for (int i = 0; i &lt; someNumber; i++) {
      if (i == expression) break;
  }
  </code></pre>
  
  <p>I'm wondering if it's more efficient to pre-calculate the expression and check against a known value like so</p>
  
  <pre><code>int known = expression;
  for (int i = 0; i &lt; known; i++) {
      // stuff
  }
  
  for (int i = 0; i &lt; someNumber; i++) {
      if (i == known) break;
  }
  </code></pre>
  
  <p>or if it's done by the compiler automatically.</p>
  
  <p>For reference, I'm running the loop ~700 000 000 times and the expression is something like <code>structure-&gt;arr[j] % n</code> or <code>sqrt(a * n + b)</code></p>
  
  <p>Is it even worth it?</p>