<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 --- - memset optimization for initialization is sometimes a pessimization"
   href="https://llvm.org/bugs/show_bug.cgi?id=24700">24700</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>memset optimization for initialization is sometimes a pessimization
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </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>LLVM Codegen
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@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>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Extracted from PR24698, consider:

union U {
 int a[2];
 int b[256];
};

void foo(int a)
{
  union U u = {.a = {1}};
  union U v = {.a = {a}};
}

Clang emits both of these as a memset of 1024 bytes followed by a store due to
our memset optimizations for initialization (see
shouldUseMemSetPlusStoresToInitialize and CheckAggExprForMemSetUse for the
constant and non-constant cases respectively). That's a pessimization: only the
first 8 bytes of u and v have specified values, so we should emit each of these
initializations as just one or two stores.

Another, more difficult to fix, version of the same problem:

struct S {
  union U a, b;
  int n;
};

void bar() {
  struct S s = { {{1}}, {{2}}, 3 };
}

This can be emitted as three or five stores, but we'll instead memset all 2K of
stack space.</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>