[llvm-bugs] [Bug 31242] New: Different code generated with -g option.

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Dec 2 13:07:12 PST 2016


https://llvm.org/bugs/show_bug.cgi?id=31242

            Bug ID: 31242
           Summary: Different code generated with -g option.
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: sunil_srivastava at playstation.sony.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

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

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20161202/9a6890f8/attachment-0001.html>


More information about the llvm-bugs mailing list