<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 - more efficient code for x % C == 0"
href="https://bugs.llvm.org/show_bug.cgi?id=35479">35479</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>more efficient code for x % C == 0
</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>Linux
</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>Common Code Generator Code
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>jay.foad@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Given:
int f(unsigned x) { return x % 25 == 0; }
clang -O3 currently (svn r319159) generates:
movl %edi, %eax
imulq $1374389535, %rax, %rax # imm = 0x51EB851F
shrq $35, %rax
leal (%rax,%rax,4), %eax
leal (%rax,%rax,4), %ecx
xorl %eax, %eax
cmpl %ecx, %edi
sete %al
Following Hacker's Delight 10-16 "Test for Zero Remainder after Division by a
Constant" it would be more efficient to generate:
imull $-1030792151, %edi, %ecx # imm = 0xC28F5C29
xorl %eax, %eax
cmpl $171798692, %ecx # imm = 0xA3D70A4
setb %al
i.e. as if the source had been:
int f(unsigned x) { return x * 0xC28F5C29 <= 0x0A3D70A3; }
The code is similar, but slightly more complicated, for even divisors, and for
signed division.</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>