<html>
    <head>
      <base href="http://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 --- - Missed SROA/DCE optimization opportunity"
   href="http://llvm.org/bugs/show_bug.cgi?id=17432">17432</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Missed SROA/DCE optimization opportunity
          </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>All
          </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>st@quanttec.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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</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>