<html>
<head>
<base href="https://llvm.org/bugs/" />
</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 --- - 64-bit divide by constant on 32-bit targets poorly optimised"
href="https://llvm.org/bugs/show_bug.cgi?id=28153">28153</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>64-bit divide by constant on 32-bit targets poorly optimised
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</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>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>simon.hosie@arm.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Given:
int64_t fn(int x) {
return x / (int64_t)1000;
}
We can see that this could trivially be implemented as a 32-bit divide, and in
turn replaced with a reciprocal multiply. Unfortunately, on 32-bit platforms
(tried ARM and x86) we get a call to a divide function instead:
asr r1, r0, #31
mov r2, #1000
mov r3, #0
bl __aeabi_ldivmod
Simply remove the cast from the constant to see preferable code:
ldr r1, .LCPI1_0
smmul r0, r0, r1
asr r1, r0, #6
add r0, r1, r0, lsr #31
asr r1, r0, #31
The cast to 64-bit comes from `X_PER_Y` constants where it might want to imply
64-bit promotion when used in multiplication. Changing the code isn't an
option because of the errors it could introduce (and it looks weird next to the
constants that do need to be 64-bit, too).</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>