[llvm-bugs] [Bug 35129] New: ptest not used for pointer comparison (but is for integer)

via llvm-bugs llvm-bugs at lists.llvm.org
Sun Oct 29 20:37:10 PDT 2017


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

            Bug ID: 35129
           Summary: ptest not used for pointer comparison (but is for
                    integer)
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: listmail at philipreames.com
                CC: llvm-bugs at lists.llvm.org

In the two snippets below, we see that instruction selection is currently
failing to select a vptest for the vector-of-pointer null test, but is using
the vptest sequence for vector-of-ints null test.

define <2 x i8*> @test_opt(<2 x i8*>* %p) {
   %ptrs = load <2 x i8*>, <2 x i8*>* %p
   %cmp = icmp eq <2 x i8*> %ptrs, zeroinitializer
   %cmp.cast = bitcast <2 x i1> %cmp to i2
   %cmp2 = icmp ne i2 %cmp.cast, 0
   br i1 %cmp2, label %slow, label %next, !perf !0
next:
   ret <2 x i8*> %ptrs
slow:
   %ptr1 = extractelement <2 x i8*> %ptrs, i32 0
   %ptr2 = extractelement <2 x i8*> %ptrs, i32 1
   call void @bar(i8* %ptr1)
   call void @bar(i8* %ptr2)
   br label %next
}

define <2 x i8*> @test_sidestep(<2 x i8*>* %p) {
   %ptrs = load <2 x i8*>, <2 x i8*>* %p
   %int.vec = ptrtoint <2 x i8*> %ptrs to <2 x i64>
   %int = bitcast <2 x i64> %int.vec to i128
   %cmp2 = icmp ne i128 %int, 0
   br i1 %cmp2, label %slow, label %next, !perf !0
next:
   ret <2 x i8*> %ptrs
slow:
   %ptr1 = extractelement <2 x i8*> %ptrs, i32 0
   %ptr2 = extractelement <2 x i8*> %ptrs, i32 1
   call void @bar(i8* %ptr1)
   call void @bar(i8* %ptr2)
   br label %next
}

Run with -mcpu=skylake, we get:
test_opt:                               # @test_opt
        .cfi_startproc
# BB#0:
        pushq   %rbx
        .cfi_def_cfa_offset 16
        subq    $16, %rsp
        .cfi_def_cfa_offset 32
        .cfi_offset %rbx, -16
        vmovdqa (%rdi), %xmm0
        vpxor   %xmm1, %xmm1, %xmm1
        vpcmpeqq        %xmm1, %xmm0, %xmm1
        vmovmskpd       %xmm1, %eax
        testb   %al, %al
        je      .LBB1_2
... trimmed irrelevant ...

test_sidestep:                          # @test_sidestep
        .cfi_startproc
# BB#0:
        pushq   %rbx
        .cfi_def_cfa_offset 16
        subq    $16, %rsp
        .cfi_def_cfa_offset 32
        .cfi_offset %rbx, -16
        vmovdqa (%rdi), %xmm0
        vptest  %xmm0, %xmm0
        je      .LBB2_2

It'd be nice if the naive pattern for a vectorized null check emitted decent
code.  :)

-- 
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/20171030/f428b72d/attachment.html>


More information about the llvm-bugs mailing list