<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][SSE] Failure to SimplifyDemandedElts through ADDSUB intrinsics"
   href="https://bugs.llvm.org/show_bug.cgi?id=46277">46277</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>[X86][SSE] Failure to SimplifyDemandedElts through ADDSUB intrinsics
          </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/KPaVBx">https://godbolt.org/z/KPaVBx</a>

We are failing to remove undemanded elements through addsub intrinsics. This
most likely needs to be handled in InstCombiner::SimplifyDemandedVectorElts,
but we might still need it in
X86TargetLowering::SimplifyDemandedVectorEltsForTargetNode as well, as we do
generate X86ISD::ADDSUB on the fly, and the SHUFFLE(FADD,FSUB) pattern might
mean that hasOneUse tests will have failed before the combine.

#include <x86intrin.h>

void test_fadd(float x, float y, float z, float w, __m128 right, float *out) {
 __m128 left = _mm_setr_ps(x, y, z, w);
 __m128 result = _mm_add_ps(left, right);
 *out++ = _mm_cvtss_f32(result);
 *out++ = _mm_cvtss_f32(_mm_shuffle_ps(result, result, _MM_SHUFFLE(1,1,1,1)));
}
void test_faddsub(float x, float y, float z, float w, __m128 right, float *out)
{
 __m128 left = _mm_setr_ps(x, y, z, w);
 __m128 result = _mm_addsub_ps(left, right);
 *out++ = _mm_cvtss_f32(result);
 *out++ = _mm_cvtss_f32(_mm_shuffle_ps(result, result, _MM_SHUFFLE(1,1,1,1)));
}

test_fadd:
  vinsertps $16, %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm1[0],xmm0[2,3]
  vaddps %xmm4, %xmm0, %xmm0
  vmovss %xmm0, (%rdi)
  vextractps $1, %xmm0, 4(%rdi)
  retq
test_faddsub:
  vinsertps $16, %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm1[0],xmm0[2,3]
  vinsertps $32, %xmm2, %xmm0, %xmm0 # xmm0 = xmm0[0,1],xmm2[0],xmm0[3]
  vinsertps $48, %xmm3, %xmm0, %xmm0 # xmm0 = xmm0[0,1,2],xmm3[0]
  vaddsubps %xmm4, %xmm0, %xmm0
  vmovss %xmm0, (%rdi)
  vextractps $1, %xmm0, 4(%rdi)
  retq

we also fail to fold the stores into movsd/movlps....</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>