[cfe-dev] -fdenormal-fp-math

Evandro Menezes via cfe-dev cfe-dev at lists.llvm.org
Fri Mar 17 07:37:31 PDT 2017


On 03/16/2017 02:09 PM, Hal Finkel wrote:
>
>
> On 03/16/2017 12:43 PM, Evandro Menezes wrote:
>> Hal,
>>
>> Would it be feasible for clang to generate crtfastmath.o on the fly 
>> at link time, by using LLVM to emit the object file?
>
> We could. We could also just inject the necessary IR into each module 
> as a linkonce_odr initialization function. I'm not sure it is 
> worthwhile; we depend on compiler-rt for a lot of optional features.

OTOH, by making sure that a module contains this code when any function 
is relaxing the FP semantics, even if the link command line doesn't 
include -ffast-math, the expected behavior can be guaranteed.

>
>>
>> On 03/16/2017 12:40 PM, Hal Finkel wrote:
>>>
>>> On 03/16/2017 11:35 AM, Evandro Menezes wrote:
>>>> Hi, Hal.
>>>>
>>>> For the benefit of all, on foil 14 in this presentation by Intel, 
>>>> https://is.gd/7Ptgwx, the issues of underflow and denormals in 
>>>> IEEE754 are explained.
>>>>
>>>> Here's what I found out in GCC:
>>>>
>>>> On {aarch64,alpha,arm,i386,ia64,mips,sparc}, when 
>>>> {-Ofast,-ffast-math,-funsafe-math-optimizations} is specified, the 
>>>> file crtfastmath.o is added to the link line.
>>>>
>>>> crtfastmath.c contains a static function with the attribute 
>>>> "constructor" that sets the appropriate flag in a control register 
>>>> to round denormals to zero.  Some targets set other bits too (like 
>>>> Alpha and i386, also to round underflows to zero, and MIPS, also to 
>>>> disable exceptions).
>>>>
>>>> Sun's SPARC compiler also flushes underflows and denormals to zero 
>>>> when the option {-fast,-fnonstd,-fns} is specified.  The reason 
>>>> given (v. https://is.gd/6jxW97) is also performance degradation.
>>>>
>>>> Since clang has a specific flag to guide the behavior of denormals, 
>>>> -fdenormal-fp-math, it could be used to make sure that the FPU is 
>>>> set to the same specified behavior: 
>>>> {ieee,preserve-sign,positive-zero}.
>>>
>>> I don't know if we can use ctrfastmath.o for this, independent of 
>>> -ffast-math, essentially because we have no control over what else 
>>> it might do, but I can certainly see shipping (e.g. as part of 
>>> compiler-rt) some similar files that specifically deal with denormals.
>>>
>>>  -Hal
>>>
>>>>   Again, specific targets might decide to imply a value other than 
>>>> "ieee" for -fdenormal-fp-math when -funsafe-math-optimizations is 
>>>> specified, either explicitly or implicitly.
>>>>
>>>> Thank you,
>>>>

Thank you,


-- 
Evandro Menezes




More information about the cfe-dev mailing list