<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </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 optimization initializing an aggregate return value by a sequence of stores"
   href="https://bugs.llvm.org/show_bug.cgi?id=47884">47884</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>missed optimization initializing an aggregate return value by a sequence of stores
          </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>enhancement
          </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>richard-llvm@metafoo.co.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Testcase:

struct Foo {
    char a;
    long b;
    char c;
    long d;
};

Foo foo1() {
    Foo f;
    f.a = 0;
    f.b = 0;
    f.c = 0;
    f.d = 0;
    return f;
}

We currently emit this as four stores to the sret parameter (1 byte, 8 byte, 1
byte, 8 byte). It would be more efficient to combine some of these stores
together.

In order for that to be correct, we'll need the frontend to tell the middle-end
that certain bytes of the sret parameter are known to be undef on entry to the
function. This seems like a general attribute we could reasonably apply to a
pointer parameter to a function, for example:

define void @foo(%struct.Foo* noalias sret(%struct.Foo) undef(32) align 8
%agg.result) {

... to indicate that the first 32 bytes reachable through %agg.result can be
assumed to be undef on entry to the function.

(We can't in general assume that sret(%T) implies that the full size of %T is
undef; that's not true in C++ due to the possibility of tail padding reuse.)</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>