[LLVMbugs] [Bug 17432] New: Missed SROA/DCE optimization opportunity

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Tue Oct 1 12:58:56 PDT 2013


http://llvm.org/bugs/show_bug.cgi?id=17432

            Bug ID: 17432
           Summary: Missed SROA/DCE optimization opportunity
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: st at quanttec.com
                CC: llvmbugs at cs.uiuc.edu
    Classification: Unclassified

test1 and test2 in the following C++ code should compile to identical machine
code, but currently don't (with the current trunk version of clang).

struct Result {
  int a;
  int b;
};

__attribute__((noinline))
void assignZero(int* p) {
  *p = 0;
}

inline Result getResult1() {  
  int a;
  assignZero(&a);
  Result result;
  result.a = a;
  result.b = a + 3;  
  return result;
}

inline Result getResult2() {  
  Result result;
  assignZero(&result.a);
  result.b = result.a + 3;
  return result;
}

__attribute__ ((noinline))
int test1() {
  return getResult1().a;
}

__attribute__ ((noinline))
int test2() {
  return getResult2().a;
}

The current trunk version of clang++ generates with "--std=c++11 -O2
-fomit-frame-pointer" the following x64 assembly:

    .globl    __Z5test1v
    .align    4, 0x90
__Z5test1v:                             ## @_Z5test1v
    .cfi_startproc
## BB#0:                                ## %entry
    pushq    %rax
Ltmp1:
    .cfi_def_cfa_offset 16
    leaq    4(%rsp), %rdi
    callq    __Z10assignZeroPi
    movl    4(%rsp), %eax
    popq    %rdx
    ret
    .cfi_endproc

    .globl    __Z5test2v
    .align    4, 0x90
__Z5test2v:                             ## @_Z5test2v
    .cfi_startproc
## BB#0:                                ## %entry
    pushq    %rax
Ltmp3:
    .cfi_def_cfa_offset 16
    leaq    (%rsp), %rdi
    callq    __Z10assignZeroPi
    movl    (%rsp), %eax
    addl    $3, %eax
    movl    %eax, 4(%rsp)
    movl    (%rsp), %eax
    popq    %rdx
    ret
    .cfi_endproc

-- 
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/20131001/3f42cf61/attachment.html>


More information about the llvm-bugs mailing list