title: Compiler generates costly MOVZX instruction
body: <p>My profiler has identified the following function profiling as the hotspot.</p>
  
  <pre><code>typedef unsigned short ushort;
  
  bool isInteriorTo( const std::vector&lt;ushort&gt;&amp; point , const ushort* coord , const ushort dim )
  {
      for( unsigned i = 0; i &lt; dim; ++i )
      {
          if( point[i + 1] &gt;= coord[i] ) return false;
      }
  
      return true;  
  }
  </code></pre>
  
  <p>In particular one assembly instruction <code>MOVZX</code> (<a href="http://x86.renejeschke.de/html/file_module_x86_id_209.html" rel="noreferrer">Move with Zero-Extend</a>) is responsible for the bulk of the runtime. The if statement is compiled into</p>
  
  <pre><code>mov     rcx, QWORD PTR [rdi]
  lea     r8d, [rax+1]
  add     rsi, 2
  movzx   r9d, WORD PTR [rsi-2]
  mov     rax, r8
  cmp     WORD PTR [rcx+r8*2], r9w
  jae     .L5
  </code></pre>
  
  <p>I'd like to coax the compiler out of generating this instruction but I suppose I first need to understand why this instruction is generated. Why the widening/zero extension, considering that I'm working with the same data type?</p>
  
  <p>(Find the entire function on <a href="https://godbolt.org/g/OJwo0F" rel="noreferrer">godbolt compiler explorer</a>.)</p>