<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - [X86] Poor vectorization array-of-bools to bitmask"
href="https://bugs.llvm.org/show_bug.cgi?id=42652">42652</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[X86] Poor vectorization array-of-bools to bitmask
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Backend: X86
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>llvm-dev@redking.me.uk
</td>
</tr>
<tr>
<th>CC</th>
<td>craig.topper@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, spatel+llvm@rotateright.com
</td>
</tr></table>
<p>
<div>
<pre><a href="https://godbolt.org/z/XHMi3b">https://godbolt.org/z/XHMi3b</a>
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
}</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>