<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 - [SLP] Failure to account for truncating stores in MinVF calculation"
   href="https://bugs.llvm.org/show_bug.cgi?id=46983">46983</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[SLP] Failure to account for truncating stores in MinVF calculation
          </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>Windows NT
          </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>llvm-dev@redking.me.uk
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>a.bataev@hotmail.com, anton.a.afanasyev@gmail.com, llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Blocks</th>
          <td>46968
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Noticed while investigating [<a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Missed SLP vectorization with umin/umax"
   href="show_bug.cgi?id=46968">Bug #46968</a>]

<a href="https://godbolt.org/z/T9Mna8">https://godbolt.org/z/T9Mna8</a>

The MinVF calculation in SLPVectorizerPass::vectorizeStoreChain is based off
the 
number of storesize elements that fix in the vector register:

const unsigned MinVF = R.getMinVecRegSize() / Sz;

But this means we fail to account for cases where we are truncating the result
just prior to the store.

Sz is set by:

unsigned BoUpSLP::getVectorElementSize(Value *V) {
  // If V is a store, just return the width of the stored value without
  // traversing the expression tree. This is the common case.
  if (auto *Store = dyn_cast<StoreInst>(V))
    return DL->getTypeSizeInBits(Store->getValueOperand()->getType());

  ...
}

So we may be able to just check for truncates feeding stores in the StoreInst
case.</pre>
        </div>
      </p>

        <div id="referenced">
          <hr style="border: 1px dashed #969696">
          <b>Referenced Bugs:</b>
          <ul>
              <li>
                [<a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Missed SLP vectorization with umin/umax"
   href="https://bugs.llvm.org/show_bug.cgi?id=46968">Bug 46968</a>] Missed SLP vectorization with umin/umax
              </li>
          </ul>
        </div>
        <br>

      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>