<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 - [InstCombine] optimize compares of abs/nabs into union/intersection of compares"
href="https://bugs.llvm.org/show_bug.cgi?id=39518">39518</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[InstCombine] optimize compares of abs/nabs into union/intersection 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>Adjusting the bug-inducing code from <a class="bz_bug_link
bz_status_NEW "
title="NEW - Incorrect optimization in InstSimplify"
href="show_bug.cgi?id=39510">bug 39510</a> to the more likely (?) pattern
shows an opportunity:
define i1 @abs_test(i32 %a) {
%cmp = icmp slt i32 %a, 0
%sub = sub nsw i32 0, %a
%abs = select i1 %cmp, i32 %sub, i32 %a
%r = icmp eq i32 %abs, 2
ret i1 %r
}
This can be reduced to logic-of-icmps:
<a href="https://rise4fun.com/Alive/FjLJ">https://rise4fun.com/Alive/FjLJ</a>
define i1 @abs_test_better(i32 %a) {
%cmp1 = icmp eq i32 %a, 2
%cmp2 = icmp eq i32 %a, -2
%r = or i1 %cmp1, %cmp2
ret i1 %r
}
----------------------------------------------------------------------------
More generally, we should be forming union/intersection patterns:
<a href="https://rise4fun.com/Alive/Rqq0">https://rise4fun.com/Alive/Rqq0</a>
Name: union
%cmp = icmp slt i32 %a, 0
%sub = sub nsw i32 0, %a
%abs = select i1 %cmp, i32 %sub, i32 %a
%r = icmp sgt i32 %abs, 42
=>
%cmp1 = icmp sgt i32 %a, 42
%cmp2 = icmp slt i32 %a, -42
%r = or i1 %cmp1, %cmp2
Name: intersection
%cmp = icmp slt i32 %a, 0
%sub = sub nsw i32 0, %a
%abs = select i1 %cmp, i32 %sub, i32 %a
%r = icmp slt i32 %abs, 42
=>
%cmp1 = icmp slt i32 %a, 42
%cmp2 = icmp sgt i32 %a, -42
%r = and i1 %cmp1, %cmp2
----------------------------------------------------------------------------
I don't have an immediate plan to work on this, but it probably needs a codegen
reversal before the IR canonicalization based on whether a target has a legal
ISD::ABS node.</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>