title: x86 binary bloat - 32-bit offsets when 8-bits would do
body: <p>I'm using clang+LLVM 2.9 to compile various workloads for x86 with the -Os option.  Small binary size is important and I must use static linking. All binaries are 32-bit.</p>
  
  <p>I notice that many instructions use addressing modes with 32-bit displacements when only 8 bits are actually used.  For example:</p>
  
  <pre><code>89 84 24 d4 00 00 00     mov    %eax,0xd4(%esp)
  </code></pre>
  
  <p>Why didn't the compiler/assembler choose the compact 8-bit displacement?</p>
  
  <pre><code>89 44 24 d4              mov    %eax,0xd4(%esp)
  </code></pre>
  
  <p>In fact, these wasted addressing bytes are over 2% of my entire binary!</p>
  
  <p>I looked at LLVM's link time optimization and tried --emit-llvm, but it didn't mention or help this issue.</p>
  
  <p>Is there some link-time optimization that can use knowledge of the actual displacements to choose the smaller instruction form?</p>
  
  <p>Thanks for any help!</p>