title: Why x86 JIT is smarter than x64?
body: <p>I'm running a very simple program</p>
  
  <pre><code>    static void Main(string[] args)
      {
          Console.WriteLine(Get4S());
          Console.WriteLine(Get4());
      }
  
      private static int Get4S()
      {
          return 4;
      }
  
      private static int Get4()
      {
          int res = 0;
          for (int i = 0; i &lt; 4; i++)
          {
              res++;
          }
          return res;
      }
  </code></pre>
  
  <p>when it works under <code>x86</code> it inlines <code>Get4S</code> method and <code>Get4</code> asm code is:</p>
  
  <pre><code>00000000  push        ebp 
  00000001  mov         ebp,esp 
  00000003  xor         eax,eax 
  00000005  inc         eax 
  00000006  inc         eax 
  00000007  inc         eax 
  00000008  inc         eax 
  00000009  pop         ebp 
  0000000a  ret 
  </code></pre>
  
  <p>BUT when running under x64 we get same asm for <code>Get4S</code> method, but <code>Get4</code> asm is not optimized at all:</p>
  
  <pre><code>00000000  xor         eax,eax 
  00000002  xor         edx,edx 
  00000004  inc         eax 
  00000006  inc         edx 
  00000008  cmp         edx,4 
  0000000b  jl          0000000000000004 
  0000000d  ret 
  </code></pre>
  
  <p>I supposed that <code>x64</code> JIT unroll the loop, then see that result can be computed in compile-time, and function with compile-time result will be inlined. But nothing from it happend. </p>
  
  <p>Why <code>x64</code> is so stupid in this case?..</p>