<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 - [X86] Failure to use MOVMSK reduction result for branches"
   href="https://bugs.llvm.org/show_bug.cgi?id=44565">44565</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[X86] Failure to use MOVMSK reduction result for branches
          </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/GLDirF">https://godbolt.org/z/GLDirF</a>

If we are selecting between 2 values using a comparison reduction then we use
the all_of/any_of MOVMSK result directly:

define i32 @select(<2 x double> %a0)  {
  %1 = fcmp ogt <2 x double> %a0, zeroinitializer
  %2 = extractelement <2 x i1> %1, i32 0
  %3 = extractelement <2 x i1> %1, i32 1
  %4 = and i1 %2, %3
  %5 = select i1 %4, i32 42, i32 88
  ret i32 %5
}

select: # @select
  vxorpd %xmm1, %xmm1, %xmm1
  vcmpltpd %xmm0, %xmm1, %xmm0
  vmovmskpd %xmm0, %eax
  cmpb $3, %al
  movl $42, %ecx
  movl $88, %eax
  cmovel %ecx, %eax
  retq

But if we decided to create a branch instead then the MOVMSK bits are used
separately, meaning we end up with 2 compares+jmps instead:

define i32 @jmp(<2 x double> %a0)  {
  %1 = fcmp ogt <2 x double> %a0, zeroinitializer
  %2 = extractelement <2 x i1> %1, i32 0
  %3 = extractelement <2 x i1> %1, i32 1
  %4 = and i1 %2, %3
  br i1 %4, label %foo, label %bar
foo:
  ret i32 42
bar:
  ret i32 88
}

jmp: # @jmp
  vxorpd %xmm1, %xmm1, %xmm1
  vcmpltpd %xmm0, %xmm1, %xmm0
  vmovmskpd %xmm0, %eax
  testb $1, %al
  je .LBB1_3
  shrb %al
  je .LBB1_3
  movl $42, %eax
  retq
.LBB1_3: # %bar
  movl $88, %eax
  retq

when I think it could be:

jmp: # @jmp
  vxorpd %xmm1, %xmm1, %xmm1
  vcmpltpd %xmm0, %xmm1, %xmm0
  vmovmskpd %xmm0, %eax
  cmp $3, %al
  jne .LBB1_3
  movl $42, %eax
  retq
.LBB1_3: # %bar
  movl $88, %eax
  retq</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>