<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 --- - Too much division"
href="https://llvm.org/bugs/show_bug.cgi?id=31028">31028</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Too much division
</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>normal
</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>filcab@gmail.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>Mentioned by Tillmann Karras.
The x86 backend emits too many idiv instructions for this function:
#include <inttypes.h>
int32_t f(int32_t a, int32_t b) {
if (a % b == 42)
return a / b;
return 3;
}
Codegen:
x86-64 (annotated):
patatino(int, int): # @patatino(int, int)
mov ecx, edi
mov eax, ecx
cdq
idiv esi # This gets us quotient in rax, remainder in rdx
mov eax, 3
cmp edx, 42
jne .LBB0_2
mov eax, ecx
cdq
idiv esi # This is useless since we already had the result
before
.LBB0_2:
ret
arm64 target (Only one divide. Different trick ("multiply-subtract"
instruction: msub)):
patatino(int, int): // @patatino(int, int)
mov w8, w0
sdiv w0, w8, w1
msub w8, w0, w1, w8
cmp w8, #42 // =42
b.eq .LBB0_2
orr w0, wzr, #0x3
.LBB0_2:
ret</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>