[llvm-dev] different output with fast-math flag

Stephen Canon via llvm-dev llvm-dev at lists.llvm.org
Tue Aug 21 09:58:06 PDT 2018


[llvm-dev to BCC]

What transformations are licensed by fast-math? Specifically, what is LLVM allowed to do with fdiv fast?

– Steve

> On Aug 21, 2018, at 12:50 PM, sangeeta chowdhary <sangitachowdhary at gmail.com> wrote:
> 
> This is of course not homework. I am trying to understand how fast math optimizations work in llvm. When I compared IR for both the programs, the only thing I have noticed is that fdiv and fmul are replaced with fdiv fast and fmul fast. Not sure what happens in fdiv fast and fmul fast.
> I feel that its because d/max is really small number and fast-math does not care about small numbers and consider them to zero but this is so incorrect. 
> 
> On Tue, Aug 21, 2018 at 12:45 PM Stephen Canon <scanon at apple.com <mailto:scanon at apple.com>> wrote:
>> On Aug 21, 2018, at 11:17 AM, sangeeta chowdhary via llvm-dev <llvm-dev at lists.llvm.org <mailto:llvm-dev at lists.llvm.org>> wrote:
>> 
>> Why the output is different for this below program when compiled using clang with fast-math optimization
>> 
>> #include<stdio.h>
>> 
>> int main() {
>>   double d = 1.0;
>>   double max = 1.79769e+308;                                                    
>>   d /= max;
>>   printf("d:%e:\n", d);
>>   d *= max;
>>   printf("d:%e:\n", d);
>>   return 0;
>> }
>> 
>> prints 0 with fast math but 1 without fast math.
> 
> Please do not ask llvm-dev to do your homework. If this is genuinely not a school assignment, reply to me off-list and I’ll help you understand what’s happening here.
> 
> – Steve

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20180821/8d01e782/attachment-0001.html>


More information about the llvm-dev mailing list