[llvm-dev] clang 4.0.0: Invalid code for builtin floating point function with -mfloat-abi=hard -ffast-math (ARM)

Friedman, Eli via llvm-dev llvm-dev at lists.llvm.org
Tue Mar 21 18:38:26 PDT 2017


On 3/21/2017 11:51 AM, Peter Jakubek via llvm-dev wrote:
> Hello,
>
> clang/llvm 4.0.0 generates invalid calls for builtin functions with 
> -mfloat-abi=hard -ffast-math.
>
> Small example fail.c:
>
>    // clang -O2 -target armv7a-none-none-eabi -mfloat-abi=hard 
> -ffast-math -S fail.c -o -
>    extern float sinf (float x);
>    float sin1 (float x) {return (sinf (x));}
>
> generates code to pass the parameter in r0 and expect the result in r0.
> The same code without -ffast-math compiles correctly. It also works 
> with -fno-builtin-sinf.
>
> (-O2 is not required to trigger the bug, but makes the resulting code 
> easier to read)
>
> It seems -ffast-math changes the internal declaration of builtin 
> functions,

It would be more accurate to say -ffast-math makes the compiler treat 
sin() as a builtin, and therefore recreate the declaration from scratch.

> as if declared
> with -mfloat-abi=soft.

That is probably unintentional.  Granted, using -mfloat-abi like this is 
kind of weird, but I think clang's behavior is supposed to be 
gcc-compatible.  See https://reviews.llvm.org/rL291909 and 
https://bugs.llvm.org/show_bug.cgi?id=30543 for the most recent work in 
this area.

CC'ing the author of that commit.

-Eli

-- 
Employee of Qualcomm Innovation Center, Inc.
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project



More information about the llvm-dev mailing list