<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] Miscompile, improper substitution of uadd.sat"
href="https://bugs.llvm.org/show_bug.cgi?id=48390">48390</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[InstCombine] Miscompile, improper substitution of uadd.sat
</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>meheff@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>$ cat >bad.ll <<EOL
define i32 @src(i32 %x1, i32 %x2) {
%x14 = add i32 %x1, %x2
%x6 = icmp ugt i32 %x14, %x2
%x9 = select i1 %x6, i32 %x14, i32 -1
ret i32 %x9
}
EOL
$ opt bad.ll --instcombine -S
; ModuleID = 'bad.ll'
source_filename = "bad.ll"
define i32 @src(i32 %x1, i32 %x2) {
%1 = call i32 @llvm.uadd.sat.i32(i32 %x2, i32 %x1)
ret i32 %1
}
; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
declare i32 @llvm.uadd.sat.i32(i32, i32) #0
attributes #0 = { nofree nosync nounwind readnone speculatable willreturn }
Alive output:
----------------------------------------
define i32 @src(i32 %x1, i32 %x2) {
%0:
%x14 = add i32 %x1, %x2
%x6 = icmp ugt i32 %x14, %x2
%x9 = select i1 %x6, i32 %x14, i32 4294967295
ret i32 %x9
}
=>
define i32 @tgt(i32 %x1, i32 %x2) {
%0:
%1 = uadd_sat i32 %x2, %x1
ret i32 %1
}
Transformation doesn't verify!
ERROR: Value mismatch
Example:
i32 %x1 = #x00000000 (0)
i32 %x2 = #x04000000 (67108864)
Source:
i32 %x14 = #x04000000 (67108864)
i1 %x6 = #x0 (0)
i32 %x9 = #xffffffff (4294967295, -1)
Target:
i32 %1 = #x04000000 (67108864)
Source value: #xffffffff (4294967295, -1)
Target value: #x04000000 (67108864)</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>