<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 does not preserve min pattern"
href="http://llvm.org/bugs/show_bug.cgi?id=20905">20905</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>instcombine does not preserve min pattern
</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>zvi.rackover@intel.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>For the following function:
define i32 @min_test(i32 %A, i32 %B) {
bb:
%tmp27 = mul nsw i32 1904000, %B
%tmp29 = mul nsw i32 2609823, %A
%tmp30 = add nsw i32 %tmp27, %tmp29
%tmp31 = sub nsw i32 %tmp30, 363703744
%tmp32 = sdiv i32 %tmp31, 1635200
%tmp50 = icmp sge i32 %tmp32, 0
%tmp51 = select i1 %tmp50, i32 %tmp32, i32 0
ret i32 %tmp51
}
After InstCombine we get:
define i32 @min_test(i32 %A, i32 %B) {
bb:
%tmp27 = mul nsw i32 %B, 1904000
%tmp29 = mul nsw i32 %A, 2609823
%tmp30 = add nsw i32 %tmp27, %tmp29
%tmp31 = add nsw i32 %tmp30, -363703744
%tmp32 = sdiv i32 %tmp31, 1635200
%tmp50 = icmp sgt i32 %tmp31, -1635200
%tmp51 = select i1 %tmp50, i32 %tmp32, i32 0
ret i32 %tmp51
}
After the transformation, the second 'icmp' operand and the third 'select'
operand do not match, and the min pattern will not be identified by Instruction
Selection, for example.
I found the following comment in InstCombine, indicating that the above
transformation is not desirable.
// Test if the ICmpInst instruction is used exclusively by a select as
// part of a minimum or maximum operation. If so, refrain from doing
// any other folding. This helps out other analyses which understand
// non-obfuscated minimum and maximum idioms, such as ScalarEvolution
// and CodeGen. And in this case, at least one of the comparison
// operands has at least one user besides the compare (the select),
// which would often largely negate the benefit of folding anyway.</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>