title: clang vs gcc: different code for volatile access
body: <p>Consider this example: </p>
  
  <pre><code>volatile unsigned int x;
  unsigned int y;
  
  void f() {
      x /= 2;
  }
  void g() {
      y /= 2;
  }
  </code></pre>
  
  <p>When compiled with -Os, clang-6.0 produces on x64 for both f and g the same <code>shrl &lt;offset&gt;(%rip)</code> instruction pattern (See <a href="https://godbolt.org/g/hUPprL" rel="noreferrer">https://godbolt.org/g/hUPprL</a>), while gcc-7.3 produces this (See <a href="https://godbolt.org/g/vMcKVV" rel="noreferrer">https://godbolt.org/g/vMcKVV</a>) for f(): </p>
  
  <pre><code> mov 0x200b67(%rip),%eax # 601034 &lt;x&gt;
   shr %eax
   mov %eax,0x200b5f(%rip) # 601034 &lt;x&gt;
  </code></pre>
  
  <p>Is this just a missed optimization or is there a justification for gcc to reject <code>shrl &lt;offset&gt;(%rip)</code> in case of volatile access? Who is wrong? </p>