<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 --- - failure to optimize a simple loop to a memset call (incorrect fear of aliasing?)"
   href="https://llvm.org/bugs/show_bug.cgi?id=27209">27209</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>failure to optimize a simple loop to a memset call (incorrect fear of aliasing?)
          </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>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>Loop Optimizer
          </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>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>LLVM fails to optimize this simple loop to a memset:

void f(char *p, char *q) {
  for (char *r = q; r != q + 256; ++r) *r = *p;
}

Presumably the relevant optimization is not firing here because of fear that p
might alias some element of the array pointed at by q. However, that doesn't
matter, because *p is the only thing written to that array, and the store size
is the same as the alignment, so *p can never actually change as a result.

See also <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Make std::fill_n use memset_pattern*() for pod types of the right size"
   href="show_bug.cgi?id=27206">https://llvm.org/bugs/show_bug.cgi?id=27206</a> -- LLVM should at least be
able to optimize that if the type of the field within struct S is char, and
should be able to hoist the load of s.i out of the loop for any type where size
== alignment. (And using C++ object lifetime rules, the hoisting is always
permitted regardless of alignment.)</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>