Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

numerical differences in x87 fpu code generated by clang-14 and clang-15 #60837

Open
anbe42 opened this issue Feb 17, 2023 · 3 comments
Open

Comments

@anbe42
Copy link

anbe42 commented Feb 17, 2023

As I've reported in Debian: https://bugs.debian.org/1031500

I've extracted a function (_Z8_cl_fmodff) from pocl generated bytecode (pocl_cl_fmod.ll, part of the pocl OpenCL implementation of float fmod(float,float)) that produces different numeric results when compiled with lvm-14 and llvm-15. I've added a small C main to demonstrate that (main.c, Makefile).
These numerical differences from pocl-3.1/llvm-15 cause test failures in pyopencl, libgpuarray.

This happens when generating 32-bit x87 fpu code with -O2 --target=i386-unknown-linux-gnu -march=i686.

$ ./test_pocl_cl_fmod_llvm14
a=0 b=0.1 c=0 d=0 abserr=0 relerr=0
a=0.1 b=0.1221239 c=0.1 d=0.1 abserr=0 relerr=0
a=0.2 b=0.14424779 c=0.055752218 d=0.055752218 abserr=0 relerr=0
a=0.3 b=0.16637169 c=0.13362832 d=0.13362832 abserr=0 relerr=0
a=0.4 b=0.18849558 c=0.023008853 d=0.023008853 abserr=0 relerr=0
a=0.5 b=0.21061946 c=0.078761071 d=0.078761071 abserr=0 relerr=0
a=0.6 b=0.23274337 c=0.13451329 d=0.13451329 abserr=0 relerr=0
a=0.7 b=0.25486726 c=0.19026548 d=0.19026548 abserr=0 relerr=0
a=0.8 b=0.27699116 c=0.24601769 d=0.24601769 abserr=0 relerr=0
a=0.9 b=0.29911503 c=0.0026548803 d=0.0026548803 abserr=0 relerr=0
$ ./test_pocl_cl_fmod_llvm15
a=0 b=0.1 c=0 d=0 abserr=0 relerr=0
a=0.1 b=0.1221239 c=0.1 d=0.1 abserr=0 relerr=0
a=0.2 b=0.14424779 c=0.055752218 d=0.055752218 abserr=0 relerr=0
a=0.3 b=0.16637169 c=0.13362832 d=0.13362832 abserr=0 relerr=0
a=0.4 b=0.18849558 c=0.023008853 d=0.023008853 abserr=0 relerr=0
a=0.5 b=0.21061946 c=0.078761071 d=0.078761071 abserr=0 relerr=0
a=0.6 b=0.23274337 c=0.13451327 d=0.13451329 abserr=1.49012e-08 relerr=6.4024e-08
a=0.7 b=0.25486726 c=0.19026548 d=0.19026548 abserr=0 relerr=0
a=0.8 b=0.27699116 c=0.24601772 d=0.24601769 abserr=-2.98023e-08 relerr=-1.07593e-07 FAIL
a=0.9 b=0.29911503 c=0.0026548505 d=0.0026548803 abserr=2.98023e-08 relerr=9.9635e-08
c = _Z8_cl_fmodff(a, b)  # from pocl
d = fmodf(a, b)          # from libc, as reference

Please get the files from https://bugs.debian.org/1031500, GitHub refused any attachment type I tried.

@llvmbot
Copy link
Collaborator

llvmbot commented Feb 17, 2023

@llvm/issue-subscribers-backend-x86

@DimitryAndric
Copy link
Collaborator

DimitryAndric commented Feb 17, 2023

This regressed (or was maybe exposed) in 0af3e6a ("[InstCombine] Sink instructions with multiple users in a successor block") by @wweiandrew (cc @nikic @preames):

$ ./pr60837-1-llvmorg-15-init-04973-gc236b41e451
a=0 b=0.1 c=0 d=0 abserr=0 relerr=0
a=0.1 b=0.1221239 c=0.1 d=0.1 abserr=0 relerr=0
a=0.2 b=0.14424779 c=0.055752218 d=0.055752218 abserr=0 relerr=0
a=0.3 b=0.16637169 c=0.13362832 d=0.13362832 abserr=0 relerr=0
a=0.4 b=0.18849558 c=0.023008853 d=0.023008853 abserr=0 relerr=0
a=0.5 b=0.21061946 c=0.078761071 d=0.078761071 abserr=0 relerr=0
a=0.6 b=0.23274337 c=0.13451329 d=0.13451329 abserr=0 relerr=0
a=0.7 b=0.25486726 c=0.19026548 d=0.19026548 abserr=0 relerr=0
a=0.8 b=0.27699116 c=0.24601769 d=0.24601769 abserr=0 relerr=0
a=0.9 b=0.29911503 c=0.0026548803 d=0.0026548803 abserr=0 relerr=0

$ ./pr60837-1-llvmorg-15-init-04974-g0af3e6a22da
a=0 b=0.1 c=0 d=0 abserr=0 relerr=0
a=0.1 b=0.1221239 c=0.1 d=0.1 abserr=0 relerr=0
a=0.2 b=0.14424779 c=0.055752218 d=0.055752218 abserr=0 relerr=0
a=0.3 b=0.16637169 c=0.13362832 d=0.13362832 abserr=0 relerr=0
a=0.4 b=0.18849558 c=0.023008853 d=0.023008853 abserr=0 relerr=0
a=0.5 b=0.21061946 c=0.078761071 d=0.078761071 abserr=0 relerr=0
a=0.6 b=0.23274337 c=0.13451327 d=0.13451329 abserr=1.49012e-08 relerr=6.4024e-08
a=0.7 b=0.25486726 c=0.19026548 d=0.19026548 abserr=0 relerr=0
a=0.8 b=0.27699116 c=0.24601772 d=0.24601769 abserr=-2.98023e-08 relerr=-1.07593e-07 FAIL

Resulting assembly for fmod.ll, compiled with -m32 -O2, using llvmorg-15-init-04973-gc236b41e451 and llvmorg-15-init-04974-g0af3e6a22da:

fmod-llvmorg-15-init-04973-gc236b41e451.s.txt
fmod-llvmorg-15-init-04974-g0af3e6a22da.s.txt

@efriedma-quic
Copy link
Collaborator

This looks like the general issue of "we don't set the precision correctly for x87 math"? As previously reported in #44218 #42470 #40569 #13862

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants