<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 - Folding a comparison to use pre-extended value results increases instructions"
   href="https://bugs.llvm.org/show_bug.cgi?id=50055">50055</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Folding a comparison to use pre-extended value results increases instructions
          </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>lebedev.ri@gmail.com, llvm-bugs@lists.llvm.org, spatel+llvm@rotateright.com
          </td>
        </tr></table>
      <p>
        <div>
        <pre><a href="https://wide.godbolt.org/z/3ob3M4qfe">https://wide.godbolt.org/z/3ob3M4qfe</a>

#include <x86intrin.h>

__m256i foo(const __m128i *src, __m256i *dst) {
  __m256i ext = _mm256_cvtepu8_epi32( _mm_loadl_epi64( src ) );
  *dst = _mm256_cmpgt_epi32( ext, _mm256_setzero_si256() );
  return ext;
}

By performing the comparison on the pre-extended source value we end up with an
additional extension, and we lose the folded load.

define <4 x i64> @foo(<2 x i64>* %0, <4 x i64>* %1) {
  %3 = getelementptr <2 x i64>, <2 x i64>* %0, i64 0, i64 0
  %4 = load i64, i64* %3, align 1
  %5 = insertelement <2 x i64> poison, i64 %4, i32 0
  %6 = bitcast <2 x i64> %5 to <16 x i8>
  %7 = shufflevector <16 x i8> %6, <16 x i8> undef, <8 x i32> <i32 0, i32 1,
i32 2, i32 3, i32 4, i32 5, i32 6, i32 7>
  %8 = zext <8 x i8> %7 to <8 x i32>
  %9 = bitcast <8 x i32> %8 to <4 x i64>
  %10 = icmp ne <8 x i8> %7, zeroinitializer
  %11 = sext <8 x i1> %10 to <8 x i32>
  %12 = bitcast <4 x i64>* %1 to <8 x i32>*
  store <8 x i32> %11, <8 x i32>* %12, align 32
  ret <4 x i64> %9
}

clang -O3 -march=haswell

foo:
        vmovq   (%rdi), %xmm1
        vpmovzxbd       %xmm1, %ymm0
        vpxor   %xmm2, %xmm2, %xmm2
        vpcmpeqb        %xmm2, %xmm1, %xmm1
        vpcmpeqd        %xmm2, %xmm2, %xmm2
        vpxor   %xmm2, %xmm1, %xmm1
        vpmovsxbd       %xmm1, %ymm1
        vmovdqa %ymm1, (%rsi)
        retq

gcc -O3 -march=haswell

foo:
        vpmovzxbd       (%rdi), %ymm0
        vpxor   %xmm1, %xmm1, %xmm1
        vpcmpgtd        %ymm1, %ymm0, %ymm1
        vmovdqa %ymm1, (%rsi)
        ret</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>