<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 - Failure to hoist constant mask out of loop"
href="https://bugs.llvm.org/show_bug.cgi?id=41272">41272</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Failure to hoist constant mask out of loop
</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/YXhpEv">https://godbolt.org/z/YXhpEv</a>
#include <stdint.h>
uint64_t sum_mask32(const uint64_t *p, int len) {
uint64_t sum = 0;
for(int i = 0; i < len; i++) {
sum += *p++ & 0x80008000;
}
return sum;
}
With clang -Os the loop kernel is:
.LBB0_4: # =>This Inner Loop Header: Depth=1
movq (%rdi,%rdx,8), %rsi
andl $-2147450880, %esi # imm = 0x80008000
addq %rsi, %rax
incq %rdx
cmpl %edx, %ecx
jne .LBB0_4
retq
With clang -O3 the unrolled kernel is even worse:
.LBB0_9: # =>This Inner Loop Header: Depth=1
movq (%rdi), %rcx
movq 8(%rdi), %rdx
andl $-2147450880, %ecx # imm = 0x80008000
addq %rax, %rcx
andl $-2147450880, %edx # imm = 0x80008000
addq %rcx, %rdx
movq 16(%rdi), %rcx
andl $-2147450880, %ecx # imm = 0x80008000
addq %rdx, %rcx
movq 24(%rdi), %rax
addq $32, %rdi
andl $-2147450880, %eax # imm = 0x80008000
addq %rcx, %rax
addl $4, %r9d
jne .LBB0_9
testl %r8d, %r8d
je .LBB0_7</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>