<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: constant comparison involving ashr is wrongly simplified."
href="http://llvm.org/bugs/show_bug.cgi?id=20945">20945</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>InstCombine: constant comparison involving ashr is wrongly simplified.
</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>Created <span class=""><a href="attachment.cgi?id=13042" name="attach_13042" title="Possible fix.">attachment 13042</a> <a href="attachment.cgi?id=13042&action=edit" title="Possible fix.">[details]</a></span>
Possible fix.
Example:
define i32 @negative_constants(i32 %B) {
entry:
%shr = ashr i32 -9, %B
%cmp = icmp ne i32 %shr, -5
br i1 %cmp, label %if.then, label %return
if.then:
br label %return
return:
%retval = phi i32 [ 0, %if.then ], [ 42, %entry ]
ret i32 %retval
}
The instruction combiner wrongly thinks that statement 'ashr i32 -9, %B' can
never evaluate to -5. Therefore, it wrongly assumes that %cmp would always be
'true' and the branch to if.then would always be taken.
In this reproducible, if %B is equal to 1, then %cmp is 'false' (since %shr
would be equal to -5).
Therefore, it is not safe to fold %cmp to 'true'. What instead should be done
is converting the comparison between %shr and -5 into a comparison between %B
and 1. This would allow us to get rid of the arithmetic shift (and eventually
simplify the CFG folding the compare-and-branch into a single select of either
0 or 42).
This is a regression introduced by revision 213678.
I attached a patch that fixes this issue (I plan to send this patch on the
mailing list for review).</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>