<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 - Incorrect InstCombine urem removal with undef values"
href="https://bugs.llvm.org/show_bug.cgi?id=38461">38461</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Incorrect InstCombine urem removal with undef values
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>All
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</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>nunoplopes@sapo.pt
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, regehr@cs.utah.edu, spatel+llvm@rotateright.com
</td>
</tr></table>
<p>
<div>
<pre>The following functions gets miscompiled:
define i2 @foo(i2, i1, i4, i2, i1, i4, i2, i1, i4, i2, i1, i4) {
%13 = urem i2 %0, -1
ret i2 %13
}
$ opt -S -instcombine urem.ll
define i2 @foo(i2, i1, i4, i2, i1, i4, i2, i1, i4, i2, i1, i4) {
%13 = icmp eq i2 %0, -1
%14 = zext i1 %13 to i2
%15 = add i2 %14, %0
ret i2 %15
}
Alive2 complains about this:
----------------------------------------
%13 = urem i2 %0, -1
ret i2 %13
=>
%13 = icmp eq i2 %0, -1
%14 = zext i1 %13 to i2
%15 = add i2 %14, %0
ret i2 %15
ERROR: Value mismatch
Example:
i2 %0 = undef
src:
i2 %13 = 0x0 (0)
tgt:
i1 %13 = 0x0 (0)
i2 %14 = 0x0 (0)
i2 %15 = 0x3 (3, -1)
Source value: 0x0 (0)
Target value: 0x3 (3, -1)
The transformation is incorrect because it increases the number of uses of %0.
Since when undef is read it may return a different value, it's not safe to
increase the number of reads like this, as is exemplified in the counterexample
above.
[P.S.: The online version of Alive unfortunately incorrectly says that this
transformation is correct. It doesn't model multiple undef uses soundly. Alive2
does, and will be available soonish]</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>