Why does gcc compile f(1199) and f(1200) differently? : <p>What causes GCC 7.2.1 on ARM to use a load from memory (<code>lr</code>) for certain constants, and an immediate (<code>mov</code>) in some other cases?  Concretely, I'm seeing the following:</p>

<p>GCC 7.2.1 for ARM compiles this:</p>

<pre><code>extern void abc(int);
int test() { abc(1199); return 0; }
</code></pre>

<p>…into that:</p>

<pre><code>test():
  push {r4, lr}
  ldr r0, .L4  // ??!
  bl abc(int)
  mov r0, #0
  pop {r4, lr}
  bx lr
.L4:
  .word 1199
</code></pre>

<p>and this:</p>

<pre><code>extern void abc(int);
int test() { abc(1200); return 0; }
</code></pre>

<p>…into that:</p>

<pre><code>test():
  push {r4, lr}
  mov r0, #1200  // OK
  bl abc(int)
  mov r0, #0
  pop {r4, lr}
  bx lr
</code></pre>

<p>At first I expected 1200 to be some sort of unique cutoff, but there are other cut-offs like this at 1024 (1024 yields a <code>mov r0, #1024</code>, whereas 1025 uses <code>ldr</code>) and at other values.</p>

<p>Why would GCC use a load from memory to fetch a constant, rather than using an immediate?</p>
