<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 - optimize ctpop codegen by width and narrow ctpop intrinsic in IR"
href="https://bugs.llvm.org/show_bug.cgi?id=43688">43688</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>optimize ctpop codegen by width and narrow ctpop intrinsic in IR
</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>All
</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>Scalar Optimizations
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>spatel+llvm@rotateright.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Spinning this off from <a class="bz_bug_link
bz_status_CONFIRMED "
title="CONFIRMED - Regression in ctpop loop vectorizer (trunk vs. llvm 9)"
href="show_bug.cgi?id=43656">bug 43656</a>:
define i32 @zpop(i8 %x) {
%z = zext i8 %x to i32
%pop = tail call i32 @llvm.ctpop.i32(i32 %z)
ret i32 %pop
}
define i32 @popz(i8 %x) {
%pop = tail call i8 @llvm.ctpop.i8(i8 %x)
%z = zext i8 %pop to i32
ret i32 %z
}
declare i8 @llvm.ctpop.i8(i8)
declare i32 @llvm.ctpop.i32(i32)
--------------------------------------------------------------------------
These are equivalent, so we should try to canonicalize them in IR. The narrow
call is likely better for vectorization and would line up with our transforms
of most math/logic ops.
But we don't have DAGCombiner and/or legalization to ensure that the narrow
call is optimized in codegen.
For example on base x86-64:
_zpop: ## @zpop
movzbl %dil, %eax
movl %eax, %ecx
shrl %ecx
andl $-43, %ecx
subl %ecx, %eax
movl %eax, %ecx
andl $858993459, %ecx ## imm = 0x33333333
shrl $2, %eax
andl $858993459, %eax ## imm = 0x33333333
addl %ecx, %eax
movl %eax, %ecx
shrl $4, %ecx
addl %eax, %ecx
andl $252645135, %ecx ## imm = 0xF0F0F0F
imull $16843009, %ecx, %eax ## imm = 0x1010101
shrl $24, %eax
retq
_popz: ## @popz
movl %edi, %eax
shrb %al
andb $85, %al
subb %al, %dil
movl %edi, %eax
andb $51, %al
shrb $2, %dil
andb $51, %dil
addb %al, %dil
movl %edi, %eax
shrb $4, %al
addb %dil, %al
andb $15, %al
movzbl %al, %eax
retq</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>