[llvm-bugs] [Bug 42652] New: [X86] Poor vectorization array-of-bools to bitmask

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jul 17 06:58:56 PDT 2019


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

            Bug ID: 42652
           Summary: [X86] Poor vectorization array-of-bools to bitmask
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Windows NT
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: llvm-dev at redking.me.uk
                CC: craig.topper at gmail.com, llvm-bugs at lists.llvm.org,
                    llvm-dev at redking.me.uk, spatel+llvm at rotateright.com

https://godbolt.org/z/XHMi3b

const unsigned count = 16;

auto BitMask(const bool *src) {
    uint64_t mask = 0;
    for (unsigned i = 0; i != count; ++i) {
      if (src[i])
        mask |= (1ull << i);
    }
    return mask;
}

This should fold to a vpcmpeqb and vpmovmskb (a <X x i1> to iX bitcast),
instead we get a massive vectorization explosion.

Increasing the count variable (or making it non-constant) is similarly awful.

define dso_local i64 @_Z7BitMaskPKb(i8* nocapture readonly) local_unnamed_addr
#0 {
  %2 = load i8, i8* %0, align 1, !tbaa !2, !range !6
  %3 = zext i8 %2 to i64
  %4 = getelementptr inbounds i8, i8* %0, i64 1
  %5 = load i8, i8* %4, align 1, !tbaa !2, !range !6
  %6 = icmp eq i8 %5, 0
  %7 = select i1 %6, i64 0, i64 2
  %8 = getelementptr inbounds i8, i8* %0, i64 2
  %9 = load i8, i8* %8, align 1, !tbaa !2, !range !6
  %10 = icmp eq i8 %9, 0
  %11 = select i1 %10, i64 0, i64 4
  %12 = getelementptr inbounds i8, i8* %0, i64 3
  %13 = load i8, i8* %12, align 1, !tbaa !2, !range !6
  %14 = icmp eq i8 %13, 0
  %15 = select i1 %14, i64 0, i64 8
  %16 = getelementptr inbounds i8, i8* %0, i64 4
  %17 = bitcast i8* %16 to <4 x i8>*
  %18 = load <4 x i8>, <4 x i8>* %17, align 1, !tbaa !2
  %19 = icmp eq <4 x i8> %18, zeroinitializer
  %20 = select <4 x i1> %19, <4 x i64> zeroinitializer, <4 x i64> <i64 16, i64
32, i64 64, i64 128>
  %21 = getelementptr inbounds i8, i8* %0, i64 8
  %22 = bitcast i8* %21 to <8 x i8>*
  %23 = load <8 x i8>, <8 x i8>* %22, align 1, !tbaa !2
  %24 = icmp eq <8 x i8> %23, zeroinitializer
  %25 = select <8 x i1> %24, <8 x i64> zeroinitializer, <8 x i64> <i64 256, i64
512, i64 1024, i64 2048, i64 4096, i64 8192, i64 16384, i64 32768>
  %26 = shufflevector <8 x i64> %25, <8 x i64> undef, <8 x i32> <i32 4, i32 5,
i32 6, i32 7, i32 undef, i32 undef, i32 undef, i32 undef>
  %27 = or <8 x i64> %25, %26
  %28 = shufflevector <8 x i64> %27, <8 x i64> undef, <8 x i32> <i32 2, i32 3,
i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
  %29 = or <8 x i64> %27, %28
  %30 = shufflevector <8 x i64> %29, <8 x i64> undef, <8 x i32> <i32 1, i32
undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef, i32 undef>
  %31 = or <8 x i64> %29, %30
  %32 = extractelement <8 x i64> %31, i32 0
  %33 = shufflevector <4 x i64> %20, <4 x i64> undef, <4 x i32> <i32 2, i32 3,
i32 undef, i32 undef>
  %34 = or <4 x i64> %20, %33
  %35 = shufflevector <4 x i64> %34, <4 x i64> undef, <4 x i32> <i32 1, i32
undef, i32 undef, i32 undef>
  %36 = or <4 x i64> %34, %35
  %37 = extractelement <4 x i64> %36, i32 0
  %38 = or i64 %32, %37
  %39 = or i64 %38, %15
  %40 = or i64 %39, %11
  %41 = or i64 %40, %7
  %42 = or i64 %41, %3
  ret i64 %42
}

-- 
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/20190717/21d76ff5/attachment.html>


More information about the llvm-bugs mailing list