<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 --- - [InstCombine] missing canonicalization for binop + compare against constant"
href="https://llvm.org/bugs/show_bug.cgi?id=27105">27105</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[InstCombine] missing canonicalization for binop + compare against constant
</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>Scalar Optimizations
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>spatel+llvm@rotateright.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>This is based on a long trail off of:
<a href="http://reviews.llvm.org/D18513">http://reviews.llvm.org/D18513</a>
int foo(int i) {
// 0x71 could be any constant
// -1 could be any constant?
// Bitwise OR could be any bitwise binop?
return (i | 0x71) == -1;
}
We can negate both sides of the equation to transform that comparison to:
int foo(int i) {
return (~i & ~0x71) == 0;
}
Now this is actually the form that we want for an x86 machine with BMI: that's
a NAND + comparison against zero - it's one instruction! It might even be worth
it for any x86 machine if a 'not' is better than an explicit compare inst.
(We still have to get the zero flag (ZF) bit into an integer register, but I
don't think there's any way to avoid that.)
But InstCombine wants to reduce the IR, so it becomes:
int foo(int i) {
return (i & ~0x71) == ~0x71;
}
So at the least, the backend has to recognize that pattern. But I think
InstCombine should be taking the original code and producing that as the
canonical form because we now have one constant instead of two.</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>