<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 - Optimizer doesn't eliminate select with two equivalent operands"
href="https://bugs.llvm.org/show_bug.cgi?id=34228">34228</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Optimizer doesn't eliminate select with two equivalent operands
</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>Linux
</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>me@manueljacob.de
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>The following transformation doesn't happen:
%shared = add i64 %x, %y
%r1 = select i1 %c1, i64 %shared, i64 %x
%r2 = select i1 %c2, i64 %shared, i64 %y
%tmp = select i1 %c2, i64 %x, i64 0
%r2_eq1 = add i64 %tmp, %y
%r2_eq2 = select i1 %zzz, i64 %r2, i64 %r2_eq1
%r = add i64 %r1, %r2_eq2
=>
%shared = add i64 %x, %y
%r1 = select i1 %c1, i64 %shared, i64 %x
%r2 = select i1 %c2, i64 %shared, i64 %y
%r = add i64 %r1, %r2
<a href="http://rise4fun.com/Alive/IOS5">http://rise4fun.com/Alive/IOS5</a>
InstCombine can do the following canonicalization (see comment in
`getSelectFoldableOperands()`):
%shared = add i64 %x, %y
%r2 = select i1 %c2, i64 %shared, i64 %y
=>
%tmp = select i1 %c2, i64 %x, i64 0
%r2 = add i64 %tmp, %y
But in this case the canonicalization doesn't happen, because %shared has two
uses. Note that %r2_eq1 actually is the canonical form of %r2. Further
canonicalization of either %r2 or %r2_eq1 won't happen. This is why the
optimizer doesn't see that %r2_eq2 selects between two equivalent operands (and
is therefore equal to %r2).</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>