<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 - In O0 optimization, -nan cannot be calculated properly."
href="https://bugs.llvm.org/show_bug.cgi?id=49305">49305</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>In O0 optimization, -nan cannot be calculated properly.
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>8.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</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>Backend: AArch64
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>2077213809@qq.com
</td>
</tr>
<tr>
<th>CC</th>
<td>arnaud.degrandmaison@arm.com, llvm-bugs@lists.llvm.org, smithp352@googlemail.com, Ties.Stuij@arm.com
</td>
</tr></table>
<p>
<div>
<pre>Simple test cases, target is aarch64-linux-gnu, The running environment is
aarch64 Linux.
#include <iostream>
#include <stdio.h>
#include <limits>
int main()
{
double a = std::numeric_limits<double>::quiet_NaN();
double b = -a;
std::cout << b << std::endl;
return 0;
}
clang++ -O0 nan_bug.cpp
./a.out
nan
clang++ -O2 nan_bug.cpp
./a.out
-nan
when we use -O0 optimize, d0 is nan, d1 is 0, and the result is still nan
15│ 0x0000000000400910 <+52>: stur d0, [x29, #-16]
16│ 0x0000000000400914 <+56>: ldur d0, [x29, #-16]
17│ 0x0000000000400918 <+60>: orr x8, xzr, #0x8000000000000000
18│ 0x000000000040091c <+64>: fmov d1, x8
19├> 0x0000000000400920 <+68>: fsub d0, d1, d0
use the (fsub 0, nan) may can't get the correct result. the x86 is correct,
it use the xor to take the negative
11│ 0x00000000004008cd <+45>: movabs $0x8000000000000000,%rcx
12│ 0x00000000004008d7 <+55>: xor %rcx,%rax
When O2 is used, -nan is directly calculated during optimization. So there's no
error.</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>