<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 - [InstCombine] Attempt to replace MOVMSK with zext (bitcast <X x i1> to iX) to i32"
   href="https://bugs.llvm.org/show_bug.cgi?id=39927">39927</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[InstCombine] Attempt to replace MOVMSK with zext (bitcast <X x i1> to iX) to i32
          </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>Backend: X86
          </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>craig.topper@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, spatel+llvm@rotateright.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre><a href="https://godbolt.org/z/SvH3do">https://godbolt.org/z/SvH3do</a>

Very similar to what we do with SSE BLENDV cases from a comparison+sext that
can be replaced with a select, we should now be able to replace MOVMSK
intrinsics with bitcasts from the comparison result.

PMOVMSKB <X x i8>
MOVMSKPS <X x float>
MOVMSKPD <X x float>

declare i32 @llvm.x86.sse2.pmovmskb.128(<16 x i8>)

define i32 @movmsk_16i8(<16 x i8>, <16 x i8>) {
  %3 = icmp sgt <16 x i8> %0, %1
  %4 = sext <16 x i1> %3 to <16 x i8>
  %5 = tail call i32 @llvm.x86.sse2.pmovmskb.128(<16 x i8> %4)
  ret i32 %5
}

define i32 @movmsk_16i8_select(<16 x i8>, <16 x i8>) {
  %3 = icmp sgt <16 x i8> %0, %1
  %4 = bitcast <16 x i1> %3 to i16
  %5 = zext i16 %4 to i32
  ret i32 %5
}

Cases where the comparison arguments don't match the MOVMSK arguments are
trickier, but this is what I've managed so far (depending on what we do with
the MOVMSK scalar result we should be able to do a lot better):

define i32 @movmsk_8i16(<8 x i16>, <8 x i16>) {
  %3 = icmp sgt <8 x i16> %0, %1
  %4 = sext <8 x i1> %3 to <8 x i16>
  %5 = bitcast <8 x i16> %4 to <16 x i8>
  %6 = tail call i32 @llvm.x86.sse2.pmovmskb.128(<16 x i8> %5)
  ret i32 %6
}

define i32 @movmsk_8i16_select(<8 x i16>, <8 x i16>) {
  %3 = icmp sgt <8 x i16> %0, %1
  %4 = sext <8 x i1> %3 to <8 x i16>
  %5 = bitcast <8 x i16> %4 to <16 x i8>
  %6 = icmp slt <16 x i8> %5, zeroinitializer
  %7 = bitcast <16 x i1> %6 to i16
  %8 = zext i16 %7 to i32
  ret i32 %8
}</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>