<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Different code generated with -g option."
   href="https://llvm.org/bugs/show_bug.cgi?id=31242">31242</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Different code generated with -g option.
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Scalar Optimizations
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>sunil_srivastava@playstation.sony.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>For the following example, the code generated by '-O2 -g' 
differs from code generated by just plain -O2.

I have tested this on the triple x86_64-unknown-linux-gnu.

This difference began with r269034. 

//----------------------------------------
extern void raf(int count, ...);
void gtest(int value) {
  raf(7, 0, 0, 0, 0, 0, 0, value);
}
void test3() {
  for (int i = 0; i <= 20; ++i) gtest(i);
}
//----------------------------------------

Looking at the generated code two points stand out:

1) In two cases, the -g version used 'movl $0,$x' to generate 
   zero, whereas the no-g version uses 'xorl $x,$x'

2) The -g version create a large enough stack frame to save
   outgoing stack arguments, and then does not change it during
   the body of test3(). It moves the outgoing args via movl
   instructions, and avoids the pop after the call to raf(). 

   The no-g version pushes the stack arguments via push instrs
   and uses a corresponding pop to restore the sp after every
   call to raf().

Here are the two versions of test,

----- Without -g ---------
_Z5test3v:
        pushq   %rbx
        xorl    %ebx, %ebx
        .p2align        4, 0x90
.LBB1_1:
        movl    $7, %edi
        xorl    %esi, %esi  <- movl in -g version
        xorl    %edx, %edx  <- movl in -g version
        xorl    %ecx, %ecx
        xorl    %r8d, %r8d
        xorl    %r9d, %r9d
        xorl    %eax, %eax
        pushq   %rbx        <- movl in -g version
        pushq   $0          <- movl in -g version
        callq   _Z3rafiz
        addq    $16, %rsp   <- not needed in -g version
        incl    %ebx
        cmpl    $21, %ebx
        jne     .LBB1_1
        popq    %rbx
        retq


----- With -g ---------
_Z5test3v:
        pushq   %rbx
        subq    $16, %rsp  
        xorl    %ebx, %ebx
        .p2align 4, 0x90
.LBB1_1:
        movl    %ebx, 8(%rsp)
        movl    $0, (%rsp)
        movl    $7, %edi
        movl    $0, %esi    <- pushl in no-g
        movl    $0, %edx    <- pushd in no-g
        xorl    %ecx, %ecx
        xorl    %r8d, %r8d
        xorl    %r9d, %r9d
        xorl    %eax, %eax
        callq   _Z3rafiz
        incl    %ebx
        cmpl    $21, %ebx
        jne     .LBB1_1
        addq    $16, %rsp
        popq    %rbx
        retq</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>