<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 - failed to eliminate pair-of-compares"
href="https://bugs.llvm.org/show_bug.cgi?id=32787">32787</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>failed to eliminate pair-of-compares
</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>enhancement
</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></table>
<p>
<div>
<pre>int foo(int x, int y) {
return x > (900 - y) || x > (450 - y);
}
Or as optimized IR:
define i32 @foo(i32 %x, i32 %y) {
%sub = sub nsw i32 900, %y
%cmp = icmp slt i32 %sub, %x
%sub1 = sub nsw i32 450, %y
%cmp2 = icmp slt i32 %sub1, %x
%narrow = or i1 %cmp, %cmp2
%z = zext i1 %narrow to i32
ret i32 %z
}
We can eliminate the first compare:
<a href="http://rise4fun.com/Alive/aC3">http://rise4fun.com/Alive/aC3</a>
We already do that (probably in InstSimplify) if the code is written as:
int foo(int x, int y) {
return (x + y) > 900 || (x + y) > 450;
}
define i32 @foo(i32 %x, i32 %y) {
%add = add nsw i32 %y, %x
%cmp2 = icmp sgt i32 %add, 450
%z = zext i1 %cmp2 to i32
ret i32 %z
}</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>