[llvm-bugs] [Bug 49304] New: In O0 optimization, -nan cannot be calculated properly.
via llvm-bugs
llvm-bugs at lists.llvm.org
Sun Feb 21 17:46:23 PST 2021
https://bugs.llvm.org/show_bug.cgi?id=49304
Bug ID: 49304
Summary: In O0 optimization, -nan cannot be calculated
properly.
Product: clang
Version: 8.0
Hardware: PC
OS: Windows NT
Status: NEW
Severity: normal
Priority: P
Component: C++11
Assignee: unassignedclangbugs at nondot.org
Reporter: 2077213809 at qq.com
CC: blitzrakete at gmail.com, dgregor at apple.com,
erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
richard-llvm at metafoo.co.uk
Simple test cases
#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, The negative operation does not seem to take effect.
The operation becomes sub 0.
the IR is
47 define dso_local i32 @main() #4 {
48 entry:
...
53 %call = call double @_ZNSt14numeric_limitsIdE9quiet_NaNEv() #3
54 store double %call, double* %a, align 8
55 %0 = load double, double* %a, align 8
56 %sub = fsub double -0.000000e+00, %0 // Desired Negative Operation
57 store double %sub, double* %b, align 8
58 %1 = load double, double* %b, align 8
...
when we use -O2, the -nan is directly calculated, so there's no problem.
%call.i6 = tail call dereferenceable(272) %"class.std::basic_ostream"*
@_ZNSo9_M_insertIdEERSoT_(%"class.std::basic_ostream"* nonnull @_ZSt4cout,
double 0xFFF8000000000000)
--
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/f8f03728/attachment.html>
More information about the llvm-bugs
mailing list