<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 merge div(x,y) with sub(x,mul(div(x,y),y)) to divrem(x,y)"
href="https://bugs.llvm.org/show_bug.cgi?id=51014">51014</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Failure to merge div(x,y) with sub(x,mul(div(x,y),y)) to divrem(x,y)
</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>Common Code Generator Code
</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>lebedev.ri@gmail.com, llvm-bugs@lists.llvm.org, spatel+llvm@rotateright.com
</td>
</tr></table>
<p>
<div>
<pre>(There's a number of similar divrem bugs but nothing covering exactly the same
issues....)
<a href="https://c.godbolt.org/z/a3YMExMqh">https://c.godbolt.org/z/a3YMExMqh</a>
<a href="https://alive2.llvm.org/ce/z/2GgRX4">https://alive2.llvm.org/ce/z/2GgRX4</a>
We fail to convert this to srem:
// only need a srem - should we do this in instcombine?
int sdivrem(int x, int y) {
int d = x / y;
int r = d - (d * y);
return r;
}
or make use of X86's divide instructions (or many divrem libcalls) also
providing the remainder:
#include <utility>
auto sdivrem_both(int x, int y) {
int d = x / y;
int r = d - (d * y);
return std::make_pair(d, r);
}
----------------------------------------
define i8 @src(i8 %a0, i8 %a1) {
%0:
%sd = sdiv i8 %a0, %a1
%mul = mul i8 %sd, %a1
%res = sub i8 %a0, %mul
ret i8 %res
}
=>
define i8 @tgt(i8 %a0, i8 %a1) {
%0:
%sd = srem i8 %a0, %a1
ret i8 %sd
}
Transformation seems to be correct!</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>