[llvm-bugs] [Bug 50055] New: Folding a comparison to use pre-extended value results increases instructions

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Apr 21 02:32:56 PDT 2021


https://bugs.llvm.org/show_bug.cgi?id=50055

            Bug ID: 50055
           Summary: Folding a comparison to use pre-extended value results
                    increases instructions
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: llvm-dev at redking.me.uk
                CC: lebedev.ri at gmail.com, llvm-bugs at lists.llvm.org,
                    spatel+llvm at rotateright.com

https://wide.godbolt.org/z/3ob3M4qfe

#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

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210421/6e5a16d0/attachment.html>


More information about the llvm-bugs mailing list