<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Reading the implementation, that’s the understatement of the century. I’ll take a look at fixing it next weekend if no one else gets to it first.</div><div class=""><br class=""></div><div class="">– Steve</div><br class=""><div><blockquote type="cite" class=""><div class="">On Sep 14, 2015, at 4:33 PM, David Majnemer via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">There is a rather unsettling comment above APFloat::mod which states "This is not currently correct in all cases."<div class=""><br class=""></div><div class="">I wonder if this is a symptom of that.</div></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Mon, Sep 14, 2015 at 12:11 PM, Zonr Chang via llvm-dev <span dir="ltr" class=""><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank" class="">llvm-dev@lists.llvm.org</a>></span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class=""><div class="">Following simple program gives different answers when compiling with GCC (4.8.4) and ToT Clang:<br class=""><br class=""></div>$ cat builtin_fmodf_bugpoint.cpp<br class=""></div>#include <cstdio><br class=""><br class=""></div>int main(int argc, char** argv) {<br class=""></div> const float a = 1.0f;<br class=""></div> const float b = 0.1f;<br class=""></div></div> printf("%f mod %f = %f\n", a, b, __builtin_fmodf(a, b));<br class=""></div> return 0;<br class=""><div class=""><div class=""><div class=""><div class=""><div class="">}<br class=""></div><div class="">$ g++ -o builtin_fmodf_bugpoint_gcc builtin_fmodf_bugpoint.cpp<br class="">$ ./builtin_fmodf_bugpoint_gcc<br class=""></div><div class="">1.000000 fmodf 0.100000 = 0.100000<br class=""></div><div class="">$ clang++ -o builtin_fmodf_bugpoint_clang builtin_fmodf_bugpoint.cpp<br class="">1.000000 fmodf 0.100000 = 0.000000<br class=""></div><div class=""><br class=""></div><div class="">Clang will compile __builtin_fmod() into LLVM's "frem" [1]. Since both operands are constant, it is constant folded by IRBuilder at the time when "frem" was built. The exeuction finally goes to llvm::ConstantFoldBinaryInstruction() which uses APFloat::mod() to compute the result. As you can see from above, it gives us 0.000000 (hex: 0x0) which is different than the answer from std::fmodf() (0.100000, hex: 0x3dcccccb).<br class=""><br class=""></div><div class="">SelectionDAG also uses APFloat::mod() to fold "frem" when operands are constants. (see SelectionDAG::getNode()). However, lli interprets "frem" to a fmod() and therefore generates the same result as GCC's.<br class=""><br class=""></div><div class="">$ lli -force-interpreter builtin_fmodf_bugpoint.ll<br class="">1.000000 fmodf 0.100000 = 0.100000<br class=""><br class=""></div><div class="">(Please refer to attachment for the .ll)<br class=""><br class=""></div><div class="">Are these expected? Which semantic does LLVM's "frem" stick to? Any idea on how to fix it?<br class=""><br class="">[1] <a href="http://llvm.org/docs/LangRef.html#i-frem" target="_blank" class="">http://llvm.org/docs/LangRef.html#i-frem</a><br class=""><br class=""></div></div></div></div></div></div>
<br class="">_______________________________________________<br class="">
LLVM Developers mailing list<br class="">
<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank" class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br class="">
<br class=""></blockquote></div><br class=""></div>
_______________________________________________<br class="">cfe-dev mailing list<br class=""><a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev<br class=""></div></blockquote></div><br class=""></body></html>