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

fabs of -0 returns -0 on Cortex-M4 #24465

Closed
llvmbot opened this issue Jul 11, 2015 · 6 comments
Closed

fabs of -0 returns -0 on Cortex-M4 #24465

llvmbot opened this issue Jul 11, 2015 · 6 comments
Assignees
Labels
bugzilla Issues migrated from bugzilla clang Clang issues not falling into any other category

Comments

@llvmbot
Copy link
Collaborator

llvmbot commented Jul 11, 2015

Bugzilla Link 24091
Resolution FIXED
Resolved on Nov 11, 2015 19:05
Version unspecified
OS Linux
Attachments test case, function that calls fabs, assembly output with clang, assembly output with gcc
Reporter LLVM Bugzilla Contributor
CC @MatzeB

Extended Description

While trying to use Clang for a microcontroller project (Cortex-M4 with FPU), I am seeing fabs(-0) returning -0. But the correct result is 0. Note, this is for calculation with doubles not floats.

Attached is a simple test case that can be compiled to assembly, and the resulting assembly, produced with the command below.

I cannot read ARM assembly well but I suspect the inlined implementation of fabs really is incorrect with respect to -0. I have also attached the result of compiling with GCC (same command line), which seems to be a much more optimized implementation.

arm-none-eabi-clang -mcpu=cortex-m4 -mthumb -O2 -fno-math-errno -fno-trapping-math -fshort-enums -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fno-rtti -fno-exceptions abs.c -S -o abs.S

Clang was configured as follows:
../configure --enable-targets=arm --target=arm-none-eabi --enable-cxx11 --disable-docs
--with-gcc-toolchain=${gcc-arm-embedded}/lib/gcc/arm-none-eabi/$gccVersion
--with-c-include-dirs=${gcc-arm-embedded}/arm-none-eabi/include

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jul 11, 2015

assigned to @MatzeB

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jul 11, 2015

Also note, trying to workaround this with "-fno-builtin-fabs" does not work. Even for the simple case when no C headers are included and instead a declaration of fabs is given with "extern double fabs(double);" (so the headers could not be replacing it with __builtin_fabs). On the other hand, "-fno-builtin" does work (but is not really a workaround considering it affects other builtins).

@MatzeB
Copy link
Contributor

MatzeB commented Jul 13, 2015

The legalization in LegalizeDAG.cpp looks wrong to me, I'll take a stab at fixing it.

@MatzeB
Copy link
Contributor

MatzeB commented Jul 14, 2015

I proposed a patch here: http://reviews.llvm.org/D11172

Could you test if it works for you?

@llvmbot
Copy link
Collaborator Author

llvmbot commented Jul 16, 2015

I have tested this patch (on top of a8eaf29, doesn't apply to latest llvm anymore). It appears to work. Thank you!

@MatzeB
Copy link
Contributor

MatzeB commented Nov 12, 2015

Finally got back to this. The proposed fix landed in 252839.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang Clang issues not falling into any other category
Projects
None yet
Development

No branches or pull requests

2 participants