title: When should I omit the frame pointer?
body: <p>Is there any substantial optimization when omitting the frame pointer?
  If I have understood correctly by reading <a href="http://gcc.gnu.org/onlinedocs/gcc-3.4.6/gcc/Optimize-Options.html" rel="noreferrer">this</a> page, <code>-fomit-frame-pointer</code> is used when we want to avoid saving, setting up and restoring frame pointers.</p>
  <p>Is this done only for each function call and if so, is it really worth to avoid a few instructions for every function?
  Isn't it trivial for an optimization.
  What are the actual implications of using this option apart from the debugging limitations?</p>
  <p>I compiled the following C code with and without this option</p>
  <pre><code>int main(void)
  {
          int i;
  
          i = myf(1, 2);
  }
  
  int myf(int a, int b)
  {
          return a + b;
  }
  </code></pre>
  <p>,</p>
  <pre><code># gcc -S -fomit-frame-pointer code.c -o withoutfp.s
  # gcc -S code.c -o withfp.s
  </code></pre>
  <p>.</p>
  <p><code>diff -u</code> 'ing the two files revealed the following assembly code:</p>
  <pre><code>
  --- withfp.s    2009-12-22 00:03:59.000000000 +0000
  +++ withoutfp.s 2009-12-22 00:04:17.000000000 +0000
  @@ -7,17 +7,14 @@
          leal    4(%esp), %ecx
          andl    $-16, %esp
          pushl   -4(%ecx)
  -       pushl   %ebp
  -       movl    %esp, %ebp
          pushl   %ecx
  -       subl    $36, %esp
  +       subl    $24, %esp
          movl    $2, 4(%esp)
          movl    $1, (%esp)
          call    myf
  -       movl    %eax, -8(%ebp)
  -       addl    $36, %esp
  +       movl    %eax, 20(%esp)
  +       addl    $24, %esp
          popl    %ecx
  -       popl    %ebp
          leal    -4(%ecx), %esp
          ret
          .size   main, .-main
  @@ -25,11 +22,8 @@
   .globl myf
          .type   myf, @function
   myf:
  -       pushl   %ebp
  -       movl    %esp, %ebp
  -       movl    12(%ebp), %eax
  -       addl    8(%ebp), %eax
  -       popl    %ebp
  +       movl    8(%esp), %eax
  +       addl    4(%esp), %eax
          ret
          .size   myf, .-myf
          .ident  "GCC: (GNU) 4.2.1 20070719 
  </code></pre>
  <p>Could someone please shed light on the <strong>key</strong> points of the above code where -fomit-frame-pointer did actually make the difference?</p>
  <p><strong>Edit:</strong> <code>objdump</code>'s output replaced with <code>gcc -S</code>'s</p>