<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">[llvm-dev to BCC]<div class=""><br class=""></div><div class="">What transformations are licensed by fast-math? Specifically, what is LLVM allowed to do with fdiv fast?</div><div class=""><br class=""></div><div class="">– Steve<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Aug 21, 2018, at 12:50 PM, sangeeta chowdhary <<a href="mailto:sangitachowdhary@gmail.com" class="">sangitachowdhary@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class="">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.<div class="">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. </div></div><br style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;" class=""><div class="gmail_quote" style="caret-color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><div dir="ltr" class="">On Tue, Aug 21, 2018 at 12:45 PM Stephen Canon <<a href="mailto:scanon@apple.com" class="">scanon@apple.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div dir="auto" style="word-wrap: break-word; line-break: after-white-space;" class=""><div style="word-wrap: break-word; line-break: after-white-space;" class=""><blockquote type="cite" class="">On Aug 21, 2018, at 11:17 AM, sangeeta chowdhary via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>> wrote:<br class=""></blockquote><div class=""><blockquote type="cite" class=""><br class="m_1500971553133381826Apple-interchange-newline"><div class=""><div dir="ltr" class=""><font face="arial, helvetica, sans-serif" class="">Why the output is different for this below program when compiled using clang with fast-math optimization</font><div class=""><font face="arial, helvetica, sans-serif" class=""><br class=""></font></div><div class=""><div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; line-height: normal; color: rgb(195, 55, 32);" class=""><font face="arial, helvetica, sans-serif" class=""><span class="m_1500971553133381826gmail-s1" style="font-variant-ligatures: no-common-ligatures; color: rgb(213, 59, 211);">#include</span><span class="m_1500971553133381826gmail-s2" style="font-variant-ligatures: no-common-ligatures;"><stdio.h></span></font></div><div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; line-height: normal; min-height: 21px;" class=""><font face="arial, helvetica, sans-serif" class=""><span class="m_1500971553133381826gmail-s2" style="font-variant-ligatures: no-common-ligatures;"></span><br class=""></font></div><div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; line-height: normal;" class=""><font face="arial, helvetica, sans-serif" class=""><span class="m_1500971553133381826gmail-s3" style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 188, 38);">int</span><span class="m_1500971553133381826gmail-s2" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>main() {</span></font></div><div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; line-height: normal;" class=""><font face="arial, helvetica, sans-serif" class=""><span class="m_1500971553133381826gmail-s2" style="font-variant-ligatures: no-common-ligatures;"><span class="m_1500971553133381826gmail-Apple-converted-space"> <span class="Apple-converted-space"> </span></span></span><span class="m_1500971553133381826gmail-s3" style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 188, 38);">double</span><span class="m_1500971553133381826gmail-s2" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>d =<span class="Apple-converted-space"> </span></span><span class="m_1500971553133381826gmail-s4" style="font-variant-ligatures: no-common-ligatures; color: rgb(195, 55, 32);">1.0</span><span class="m_1500971553133381826gmail-s2" style="font-variant-ligatures: no-common-ligatures;">;</span></font></div><div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; line-height: normal;" class=""><font face="arial, helvetica, sans-serif" class=""><span class="m_1500971553133381826gmail-s5" style="font-variant-ligatures: no-common-ligatures;"><span class="m_1500971553133381826gmail-Apple-converted-space"> <span class="Apple-converted-space"> </span></span></span><span class="m_1500971553133381826gmail-s6" style="font-variant-ligatures: no-common-ligatures; color: rgb(52, 188, 38);">double</span><span class="m_1500971553133381826gmail-s5" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span>max =<span class="Apple-converted-space"> </span></span><span class="m_1500971553133381826gmail-s7" style="font-variant-ligatures: no-common-ligatures; color: rgb(195, 55, 32);">1.79769e+308</span><span class="m_1500971553133381826gmail-s5" style="font-variant-ligatures: no-common-ligatures;">;<span class="Apple-converted-space"> </span><span class="m_1500971553133381826gmail-Apple-converted-space">                                                   </span></span></font></div><div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; line-height: normal;" class=""><span class="m_1500971553133381826gmail-s2" style="font-variant-ligatures: no-common-ligatures;"><font face="arial, helvetica, sans-serif" class=""><span class="m_1500971553133381826gmail-Apple-converted-space"> <span class="Apple-converted-space"> </span></span>d /= max;</font></span></div><div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; line-height: normal;" class=""><font face="arial, helvetica, sans-serif" class=""><span class="m_1500971553133381826gmail-s2" style="font-variant-ligatures: no-common-ligatures;"><span class="m_1500971553133381826gmail-Apple-converted-space"> <span class="Apple-converted-space"> </span></span>printf(</span><span class="m_1500971553133381826gmail-s4" style="font-variant-ligatures: no-common-ligatures; color: rgb(195, 55, 32);">"d:</span><span class="m_1500971553133381826gmail-s1" style="font-variant-ligatures: no-common-ligatures; color: rgb(213, 59, 211);">%e</span><span class="m_1500971553133381826gmail-s4" style="font-variant-ligatures: no-common-ligatures; color: rgb(195, 55, 32);">:</span><span class="m_1500971553133381826gmail-s1" style="font-variant-ligatures: no-common-ligatures; color: rgb(213, 59, 211);">\n</span><span class="m_1500971553133381826gmail-s4" style="font-variant-ligatures: no-common-ligatures; color: rgb(195, 55, 32);">"</span><span class="m_1500971553133381826gmail-s2" style="font-variant-ligatures: no-common-ligatures;">, d);</span></font></div><div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; line-height: normal;" class=""><span class="m_1500971553133381826gmail-s2" style="font-variant-ligatures: no-common-ligatures;"><font face="arial, helvetica, sans-serif" class=""><span class="m_1500971553133381826gmail-Apple-converted-space"> <span class="Apple-converted-space"> </span></span>d *= max;</font></span></div><div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; line-height: normal;" class=""><font face="arial, helvetica, sans-serif" class=""><span class="m_1500971553133381826gmail-s2" style="font-variant-ligatures: no-common-ligatures;"><span class="m_1500971553133381826gmail-Apple-converted-space"> <span class="Apple-converted-space"> </span></span>printf(</span><span class="m_1500971553133381826gmail-s4" style="font-variant-ligatures: no-common-ligatures; color: rgb(195, 55, 32);">"d:</span><span class="m_1500971553133381826gmail-s1" style="font-variant-ligatures: no-common-ligatures; color: rgb(213, 59, 211);">%e</span><span class="m_1500971553133381826gmail-s4" style="font-variant-ligatures: no-common-ligatures; color: rgb(195, 55, 32);">:</span><span class="m_1500971553133381826gmail-s1" style="font-variant-ligatures: no-common-ligatures; color: rgb(213, 59, 211);">\n</span><span class="m_1500971553133381826gmail-s4" style="font-variant-ligatures: no-common-ligatures; color: rgb(195, 55, 32);">"</span><span class="m_1500971553133381826gmail-s2" style="font-variant-ligatures: no-common-ligatures;">, d);</span></font></div><div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; line-height: normal; color: rgb(205, 121, 35);" class=""><font face="arial, helvetica, sans-serif" class=""><span class="m_1500971553133381826gmail-s8" style="font-variant-ligatures: no-common-ligatures;"><span class="m_1500971553133381826gmail-Apple-converted-space"> <span class="Apple-converted-space"> </span></span></span><span class="m_1500971553133381826gmail-s2" style="font-variant-ligatures: no-common-ligatures;">return</span><span class="m_1500971553133381826gmail-s8" style="font-variant-ligatures: no-common-ligatures;"><span class="Apple-converted-space"> </span></span><span class="m_1500971553133381826gmail-s4" style="font-variant-ligatures: no-common-ligatures; color: rgb(195, 55, 32);">0</span><span class="m_1500971553133381826gmail-s8" style="font-variant-ligatures: no-common-ligatures;">;</span></font></div><div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; line-height: normal;" class=""><span class="m_1500971553133381826gmail-s2" style="font-variant-ligatures: no-common-ligatures;"><font face="arial, helvetica, sans-serif" class="">}</font></span></div><div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; line-height: normal;" class=""><span class="m_1500971553133381826gmail-s2" style="font-variant-ligatures: no-common-ligatures;"><font face="arial, helvetica, sans-serif" class=""><br class=""></font></span></div><div style="margin: 0px; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; line-height: normal;" class=""><span style="font-variant-ligatures: no-common-ligatures;" class=""><font face="arial, helvetica, sans-serif" class="">prints 0 with fast math but 1 without fast math.</font></span></div></div></div></div></blockquote><br class=""></div><div class="">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.</div><div class=""><br class=""></div><div class="">– Steve</div></div></div></blockquote></div></div></blockquote></div><br class=""></div></body></html>