[cfe-dev] -fdenormal-fp-math

Hal Finkel via cfe-dev cfe-dev at lists.llvm.org
Thu Mar 16 12:09:55 PDT 2017


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.

  -Hal

>
> Thank you,
>
> -- 
> Evandro Menezes
>
> 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,
>>>
>>
>

-- 
Hal Finkel
Lead, Compiler Technology and Programming Languages
Leadership Computing Facility
Argonne National Laboratory

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20170316/e000e874/attachment.html>


More information about the cfe-dev mailing list