[llvm-bugs] [Bug 49305] New: In O0 optimization, -nan cannot be calculated properly.
via llvm-bugs
llvm-bugs at lists.llvm.org
Sun Feb 21 18:33:17 PST 2021
https://bugs.llvm.org/show_bug.cgi?id=49305
Bug ID: 49305
Summary: In O0 optimization, -nan cannot be calculated
properly.
Product: libraries
Version: 8.0
Hardware: PC
OS: Windows NT
Status: NEW
Severity: normal
Priority: P
Component: Backend: AArch64
Assignee: unassignedbugs at nondot.org
Reporter: 2077213809 at qq.com
CC: arnaud.degrandmaison at arm.com,
llvm-bugs at lists.llvm.org, smithp352 at googlemail.com,
Ties.Stuij at arm.com
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.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210222/057b4bad/attachment-0001.html>
More information about the llvm-bugs
mailing list