[llvm-bugs] [Bug 47448] New: x86 SSE2&AVX2 regression, unfortunate instruction selection for vectorized i8 and i16 comparisons due to overzealous conversion to unsigned.

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Sep 7 06:00:47 PDT 2020


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

            Bug ID: 47448
           Summary: x86 SSE2&AVX2 regression, unfortunate instruction
                    selection for vectorized i8 and i16 comparisons due to
                    overzealous conversion to unsigned.
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: ToHe_EMA at gmx.de
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org

While writing custom code to handle vectorized loop remainder I noticed that
the current LLVM trunk sometimes turns "signed greater than" SSE2-intrinsics
into "unsigned greater than or equal" which are not directly supported by SSE2.
The problem occurs with both i8 and i16 integer vectors and with SSE2 as well
as AVX2.

Here is some C code that illustrates the problem:

#include <emmintrin.h>
__m128i BadCompare(short value)
{
    return _mm_cmpgt_epi16(
        _mm_set1_epi16(value & 7),
        _mm_setr_epi16(0, 1, 2, 3, 4, 5, 6, 7));
}

This compiles to the following assembly (https://gcc.godbolt.org/z/nx5Pn4):

.LCPI0_0:
        .short  1
        .short  2
        .short  3
        .short  4
        .short  5
        .short  6
        .short  7
        .short  8
BadCompare(short):
        and     edi, 7
        movd    xmm0, edi
        pshuflw xmm0, xmm0, 0
        pshufd  xmm0, xmm0, 0
        movdqa  xmm1, xmmword ptr [rip + .LCPI0_0]
        psubusw xmm1, xmm0                            # !!!
        pxor    xmm0, xmm0                            # !!!
        pcmpeqw xmm0, xmm1                            # !!!
        ret

The generated code is suboptimal because "pcmpgt" should be used as requested
instead of incrementing all numbers and using "psubusw" and "pcmpeqw". 

It seems to me that the regression is caused by some earlier pass in LLVM now
converting "icmp sgt" into "icmp ugt" which is indeed a valid transformation
because of the "& 7". For i32 and i64 integer vectors the x86 backend appears
to undo this conversion. However this step is either broken or missing in the
i8 and i16 case.

-- 
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/20200907/54263265/attachment-0001.html>


More information about the llvm-bugs mailing list