<html>
<head>
<base href="http://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: wrong folding of a constant comparison involving ashr and negative numbers."
href="http://llvm.org/bugs/show_bug.cgi?id=21222">21222</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>InstCombine: wrong folding of a constant comparison involving ashr and negative numbers.
</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>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>andrea.dibiagio@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Reproducible:
;;
define i1 @test(i32 %B) {
%shr = ashr i32 -93, %B
%cmp = icmp eq i32 %shr, -2
ret i1 %cmp
}
;;
Function @test should return true when %B is equal to 6.
That is because -93 >> 6 = -2.
Currently the Instruction Combiner wrongly folds the entire function to a
`return i1 false`.
The problem is in the folding logic located in InstCombineCompares.cpp; method
InstCombiner::FoldICmpCstShrCst wrongly computes the distance (in binary)
between two negative values.
With:
AP1 < 0
AP2 < 0
AP2 != 0
AP1 != 0
AP1 > AP2
Currently the distance between AP2 and AP1 is wrongly computed as:
(-AP2).logBase2() - (-AP1).logBase2()
the distance between AP1 and AP2 should be computed instead taking the ones'
complement of AP2 and AP1:
(~AP2).logBase2() - (~AP1).logBase2()
This is another regression introduced by revision 213678 which, unfortunately
wasn't correctly fixed by revision 217950.
I have a fix for this bug which I plan to send soon for review on the mailing
list.</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>