<html>
    <head>
      <base href="https://llvm.org/bugs/" />
    </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, SSE] failed to simplify vector select with zero constant to 'and'"
   href="https://llvm.org/bugs/show_bug.cgi?id=28895">28895</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[x86, SSE] failed to simplify vector select with zero constant to 'and'
          </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>All
          </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>Backend: X86
          </td>
        </tr>

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

        <tr>
          <th>Reporter</th>
          <td>spatel+llvm@rotateright.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>While looking at the select fold in <a href="https://reviews.llvm.org/D22975">https://reviews.llvm.org/D22975</a>, I noticed
this problem:

define <4 x float> @fselvec(<4 x float> %x, <4 x float> %y) {
  %cmp = fcmp oeq <4 x float> %x, zeroinitializer
  %sel = select <4 x i1> %cmp, <4 x float> %y, <4 x float> zeroinitializer
  ret <4 x float> %sel
}

This should be an 'and' bitwise logic op, but:

$ ./llc  fsel.ll -o -  -mattr=avx
    vxorps    %xmm2, %xmm2, %xmm2
    vcmpeqps    %xmm2, %xmm0, %xmm0
    vblendvps    %xmm0, %xmm1, %xmm2, %xmm0
    retq


The optimization exists for AArch64:

$ ./llc  fsel.ll -o -  -mtriple=aarch64
    fcmeq    v0.4s, v0.4s, #0.0
    and    v0.16b, v1.16b, v0.16b
    ret

The optimization also exists for x86 FP scalar and x86 integer vector, so some
refactoring may be needed:

define float @fsel(float %x, float %y) {
  %cmp = fcmp oeq float %x, 0.0
  %sel = select i1 %cmp, float %y, float 0.0
  ret float %sel
}

define <4 x i32> @iselvec(<4 x i32> %x, <4 x i32> %y) {
  %cmp = icmp eq <4 x i32> %x, zeroinitializer
  %sel = select <4 x i1> %cmp, <4 x i32> %y, <4 x i32> zeroinitializer
  ret <4 x i32> %sel
}

_fsel:                                  ## @fsel
    vxorps    %xmm2, %xmm2, %xmm2
    vcmpeqss    %xmm2, %xmm0, %xmm0
    vandps    %xmm1, %xmm0, %xmm0
    retq

_iselvec:                               ## @iselvec
    vpxor    %xmm2, %xmm2, %xmm2
    vpcmpeqd    %xmm2, %xmm0, %xmm0
    vpand    %xmm1, %xmm0, %xmm0
    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>