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: unassignedclangb...@nondot.org
          Reporter: 2077213...@qq.com
                CC: blitzrak...@gmail.com, dgre...@apple.com,
                    erik.pilking...@gmail.com, llvm-bugs@lists.llvm.org,
                    richard-l...@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to