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: unassignedb...@nondot.org
          Reporter: 2077213...@qq.com
                CC: arnaud.degrandmai...@arm.com,
                    llvm-bugs@lists.llvm.org, smithp...@googlemail.com,
                    ties.st...@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.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to