<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 - [GlobalISel] When widening from non-power of 2, Legalizer assumes zero-extending loads"
   href="https://bugs.llvm.org/show_bug.cgi?id=43288">43288</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[GlobalISel] When widening from non-power of 2, Legalizer assumes zero-extending loads
          </td>
        </tr>

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

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

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Windows NT
          </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>GlobalISel
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>alex.davies@iinet.net.au
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org, quentin.colombet@gmail.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Legalizer assumes G_LOAD clears upper bits.

This is clearest in the comments:

        // Our strategy here is to generate anyextending loads for the smaller
        // types up to next power-2 result type, and then combine the two
larger
        // result values together, before truncating back down to the non-pow-2
        // type.
        // E.g. v1 = i24 load =>
        // v2 = i32 load (2 byte)
        // v3 = i32 load (1 byte)
        // v4 = i32 shl v3, 16
        // v5 = i32 or v4, v2
        // v1 = i24 trunc v5


v2 receives an G_ANYEXT load, so upper 16 bits are undefined. v5 then ors these
upper bits, and hopes to get something meaningful from the result => bug.

Proposed fix:

        // E.g. v1 = i24 load =>
        // v2 = zext(i16 load (2 byte))
        // v3 = i32 load (1 byte)

And in code:

        auto LargeLoad =
            MIRBuilder.buildLoad(LargeLdReg, PtrReg, *LargeMMO);

becomes:

        auto LargeLoad = MIRBuilder.buildZExt(LargeLdReg,
MIRBuilder.buildLoad(LLT::scalar(LargeSplitSize), PtrReg, *LargeMMO));

Despite the bug, the code _usually_ turns out correctly (until I managed to
break it adding a few more artifact combiners...), although this seems to be
mostly by luck as far as I can tell.</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>