<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_ASSIGNED "
title="ASSIGNED --- - Preserving nsw/nuw for x-(-A)=>x+A is unsafe"
href="http://llvm.org/bugs/show_bug.cgi?id=20189">20189</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Preserving nsw/nuw for x-(-A)=>x+A is unsafe
</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>ASSIGNED
</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>wujingyue@gmail.com
</td>
</tr>
<tr>
<th>Reporter</th>
<td>wujingyue@gmail.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>When optimizing x-(-A) to x+A, the current logic of preserving nsw/nuw has a
hole.
For example, the current logic transforms "x -nsw (0-A)" to "x +nsw A".
However, when x = a = INT_MIN = -2^31, "x -nsw (0 - A)" is defined but "x +nsw
A"
returns a poison value. The following test case exposes the bug.
define i32 @test37(i32 %A, i32 %x) {
%B = sub i32 0, %A
%C = sub nsw i32 %x, %B
ret i32 %C
; CHECK-LABEL: @test37(
; CHECK: %C = add i32 %x, %A
; CHECK: ret i32 %C
}
To fix this issue, we need to consider the nsw/nuw of both minuses in x-(-A).
If both of them are marked nsw/nuw, we can preserve the nsw/nuw in the result
x+A.</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>