<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 - Wrong codegen for i1 vector truncating stores"
   href="https://bugs.llvm.org/show_bug.cgi?id=35520">35520</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Wrong codegen for i1 vector truncating stores
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>Other
          </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>Common Code Generator Code
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>uweigand@de.ibm.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@justinbogner.com, llvm-bugs@lists.llvm.org, Matthew.Arsenault@amd.com, paulsson@linux.vnet.ibm.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>The following simple test case generates completely broken code on SystemZ (run
with -mcpu=z13 to enable the vector ISA):

define i16 @test(<16 x i1> %src)
{
  %res = bitcast <16 x i1> %src to i16
  ret i16 %res
}

What happens is that in the ABI, the <16 x i1> is passed as <16 x i8>, so the
code would need to truncate to a real 16-bit vector, and reinterpret the result
as i16.  For some reason, the code generator attempts to implement this as a
truncating store of a <16 x i8> in register to a <16 x i1> in memory, and then
loads that memory location as i16.

So far still OK, but the truncating store generates completely broken code: it
simply repeatedly stores all 16 bytes of the source vector to the same byte in
memory.  Looking for the code that does this, I found this in
VectorLegalizer::ExpandStore (added by arsenm):

    // FIXME: This is completely broken and inconsistent with ExpandLoad
    // handling.

    // For sub-byte element sizes, this ends up with 0 stride between elements,
    // so the same element just gets re-written to the same location. There
seem
    // to be tests explicitly testing for this broken behavior though.  tests
    // for this broken behavior.

which in fact matches exactly what I'm seeing.

What's going on here?  Does this not happen on other platforms?  Should I be
doing something different in the back-end, or should we try to fix this common
code issue after all?  Any suggestions welcome ...</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>