[llvm-bugs] [Bug 42035] New: Missed simplifications for PTEST patterns

via llvm-bugs llvm-bugs at lists.llvm.org
Mon May 27 10:21:31 PDT 2019


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

            Bug ID: 42035
           Summary: Missed simplifications for PTEST patterns
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: david.bolvansky at gmail.com
                CC: craig.topper at gmail.com, llvm-bugs at lists.llvm.org,
                    llvm-dev at redking.me.uk, spatel+llvm at rotateright.com

As mentioned in
https://mattkretz.github.io/2019/05/27/vectorized-conversion-from-utf8-using-stdx-simd.html
and related created issue on GCC's bugzilla, there are opportunities to
simplify PTEST patterns and neither GCC nor Clang can optimize it currently.

Test cases from GCC's bugzilla:
using __v16qu [[gnu::vector_size(16)]] = unsigned char;

// test sign bit [ptest 0x808080..., x]
bool bad(__v16qu x) {
  return __builtin_ia32_ptestz128(~__v16qu(), x > 0x7f);
}

bad(unsigned char __vector(16)): // test for the sign bit, we can optimize to
(with 0x808080... at LC0)
        vpxor   xmm1, xmm1, xmm1
        vpcmpgtb        xmm0, xmm1, xmm0
        vpcmpeqd        xmm1, xmm1, xmm1
        vptest  xmm1, xmm0
        sete    al
        ret

// test for zero [ptest x, x]
bool bad2(__v16qu x) {
  return __builtin_ia32_ptestz128(~__v16qu(), x == 0);
}

bad2(unsigned char __vector(16)): //  equivalent to testing scalars for 0
        vpxor   %xmm1, %xmm1, %xmm1
        vpcmpeqb        %xmm1, %xmm0, %xmm0
        vpcmpeqd        %xmm1, %xmm1, %xmm1
        vptest  %xmm0, %xmm1
        sete    %al
        ret

// test for certain bits [ptest x, k]
bool bad3(__v16qu x, __v16qu k) {
  return __builtin_ia32_ptestz128(~__v16qu(), (x & k) == 0);
}

bad3(unsigned char __vector(16), unsigned char __vector(16)):
        vpand   xmm0, xmm1, xmm0
        vpxor   xmm1, xmm1, xmm1
        vpcmpeqb        xmm0, xmm0, xmm1
        vpcmpeqd        xmm1, xmm1, xmm1
        vptest  xmm1, xmm0
        sete    al
        ret

With the above transformation we already get PTEST(x&k, x&k) which can
consequently be reduced to PTEST(x, k):

-- 
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/20190527/6cc1547a/attachment.html>


More information about the llvm-bugs mailing list