title: Why are gcc and clang not hoisting strlen out of this loop?
body: <p>Consider the following code:</p>
  
  <pre><code>#include &lt;string.h&gt;
  
  void bar(char c);
  
  void foo(const char* restrict ss) {
      for (int i = 0; i &lt; strlen(ss); ++i) {
          bar(*ss);
      }
  }    
  </code></pre>
  
  <p>I would expect the <code>strlen(ss)</code> to be hoisted out of the loop in these essentially ideal conditions; and yet - <a href="https://godbolt.org/g/vdGSBe" rel="nofollow noreferrer">it isn't, neither by clang 5.0 nor by gcc 7.3</a> with maximum optimization (<code>-O3</code>).</p>
  
  <p>Why is this the case?</p>
  
  <p>Note: Inspired by (my answer to) <a href="https://stackoverflow.com/a/48481978/1593077">this question</a>.</p>