<html>
<head>
<base href="https://llvm.org/bugs/" />
</head>
<body><span class="vcard"><a class="email" href="mailto:spatel+llvm@rotateright.com" title="Sanjay Patel <spatel+llvm@rotateright.com>"> <span class="fn">Sanjay Patel</span></a>
</span> changed
<a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED FIXED - Integer divide by constant close to UINT*_MAX can be compare rather than divide"
href="https://llvm.org/bugs/show_bug.cgi?id=28672">bug 28672</a>
<br>
<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>What</th>
<th>Removed</th>
<th>Added</th>
</tr>
<tr>
<td style="text-align:right;">Status</td>
<td>NEW
</td>
<td>RESOLVED
</td>
</tr>
<tr>
<td style="text-align:right;">Resolution</td>
<td>---
</td>
<td>FIXED
</td>
</tr></table>
<p>
<div>
<b><a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED FIXED - Integer divide by constant close to UINT*_MAX can be compare rather than divide"
href="https://llvm.org/bugs/show_bug.cgi?id=28672#c3">Comment # 3</a>
on <a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED FIXED - Integer divide by constant close to UINT*_MAX can be compare rather than divide"
href="https://llvm.org/bugs/show_bug.cgi?id=28672">bug 28672</a>
from <span class="vcard"><a class="email" href="mailto:spatel+llvm@rotateright.com" title="Sanjay Patel <spatel+llvm@rotateright.com>"> <span class="fn">Sanjay Patel</span></a>
</span></b>
<pre>I'm marking this as fixed with:
<a href="https://reviews.llvm.org/rL282209">https://reviews.llvm.org/rL282209</a>
...because that gets rid of the urem in InstCombine.
There are a couple of potential follow-up bugs:
1. As noted, we can extend this transform even for non-constant divisors if we
can prove that the MSB (the sign bit) is set.
2. The backend doesn't seem to recognize negated constants:
ARM:
@ BB#0: @ %entry
ldr r2, .LCPI0_0
ldr r3, .LCPI0_1
add r1, r0, #1
cmp r1, r3
addhs r1, r0, r2
mov r0, r1
bx lr
.p2align 2
@ BB#1:
.LCPI0_0:
.long 294397890 @ 0x118c27c2
.LCPI0_1:
.long 4000569407 @ 0xee73d83f
x86:
leal 1(%rdi), %ecx
leal 294397890(%rdi), %eax
cmpl $-294397889, %ecx ## imm = 0xEE73D83F
cmovbl %ecx, %eax
retq</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>