<html><head></head><body><div style="color:#000; background-color:#fff; font-family:Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:13px"><div id="yui_3_16_0_ym19_1_1493303473235_6207"><o:p id="yui_3_16_0_ym19_1_1493303473235_6208"> </o:p></div><div id="yui_3_16_0_ym19_1_1493303473235_6209">Hi,<o:p id="yui_3_16_0_ym19_1_1493303473235_6210"></o:p></div><div id="yui_3_16_0_ym19_1_1493303473235_6211"><o:p id="yui_3_16_0_ym19_1_1493303473235_6212"> </o:p></div><div id="yui_3_16_0_ym19_1_1493303473235_6213" dir="ltr">I have an implementation for extending the target library
info with additional math functions that get called when the header files pull
in alternative versions during the use of –ffast-math so that calls to those can
be optimized (http://lists.llvm.org/pipermail/llvm-dev/2017-March/111323.html).</div><div id="yui_3_16_0_ym19_1_1493303473235_6213" dir="ltr"><br></div><div id="yui_3_16_0_ym19_1_1493303473235_6213" dir="ltr">I’m hoping someone can perform a code review and commit for me. When
I tried to select ‘llvm-commits’ in the subscriber list of Phabricator, the name is crossed
out for me, and mails do not seem to be going out for it, so I’m sending mail here. (If anybody knows why it is crossed out,
and how I can fix this, please let me know).<br></div><div id="yui_3_16_0_ym19_1_1493303473235_6213" dir="ltr"><o:p id="yui_3_16_0_ym19_1_1493303473235_6214"></o:p></div><div id="yui_3_16_0_ym19_1_1493303473235_6215"><o:p id="yui_3_16_0_ym19_1_1493303473235_6216"> </o:p></div><div id="yui_3_16_0_ym19_1_1493303473235_6217">Anyway, if someone could review the code changes posted,
that would be greatly appreciated. I have broken down the changes into 3 changesets to
minimize the deltas for each.<o:p id="yui_3_16_0_ym19_1_1493303473235_6218"></o:p></div><div style="margin-left:.5in" id="yui_3_16_0_ym19_1_1493303473235_6219"><a href="https://reviews.llvm.org/D31787" id="yui_3_16_0_ym19_1_1493303473235_6220">https://reviews.llvm.org/D31787</a><o:p id="yui_3_16_0_ym19_1_1493303473235_6221"></o:p></div><div style="margin-left:.5in" id="yui_3_16_0_ym19_1_1493303473235_6222"><a href="https://reviews.llvm.org/D31788" id="yui_3_16_0_ym19_1_1493303473235_6223">https://reviews.llvm.org/D31788</a><o:p id="yui_3_16_0_ym19_1_1493303473235_6224"></o:p></div><div style="margin-left:.5in" id="yui_3_16_0_ym19_1_1493303473235_6225"><a href="https://reviews.llvm.org/D31789" id="yui_3_16_0_ym19_1_1493303473235_6226">https://reviews.llvm.org/D31789</a><o:p id="yui_3_16_0_ym19_1_1493303473235_6227"></o:p></div><div id="yui_3_16_0_ym19_1_1493303473235_6228"><o:p id="yui_3_16_0_ym19_1_1493303473235_6229"> </o:p></div><div id="yui_3_16_0_ym19_1_1493303473235_6228"><o:p><br></o:p></div><div id="yui_3_16_0_ym19_1_1493303473235_6230">Thanks,<o:p id="yui_3_16_0_ym19_1_1493303473235_6231"></o:p></div><div id="yui_3_16_0_ym19_1_1493303473235_6098">





















</div><div dir="ltr" id="yui_3_16_0_ym19_1_1493303473235_6232">Chris<o:p id="yui_3_16_0_ym19_1_1493303473235_6233"></o:p></div><div dir="ltr" id="yui_3_16_0_ym19_1_1493303473235_6232"><br></div> <div class="qtdSeparateBR"><br><br></div><div class="yahoo_quoted" style="display: block;"> <div style="font-family: Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 13px;"> <div style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"> <div dir="ltr"><font size="2" face="Arial"> On Monday, March 20, 2017 3:46 PM, Chris Chrulski via llvm-dev <llvm-dev@lists.llvm.org> wrote:<br></font></div>  <br><br> <div class="y_msg_container"><div id="yiv3951454861"><div><div style="color:#000;background-color:#fff;font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px;"><div id="yiv3951454861yui_3_16_0_ym19_1_1489792973092_101008"><span id="yiv3951454861yui_3_16_0_ym19_1_1489792973092_101009">Thanks Hal,</span></div><div id="yiv3951454861yui_3_16_0_ym19_1_1489792973092_101010"><br clear="none" id="yiv3951454861yui_3_16_0_ym19_1_1489792973092_101011"></div><div dir="ltr" id="yiv3951454861yui_3_16_0_ym19_1_1489792973092_101012"><span id="yiv3951454861yui_3_16_0_ym19_1_1489792973092_101013">I'll take a look into extending the TargetLibraryInfo.</span></div><div dir="ltr" id="yiv3951454861yui_3_16_0_ym19_1_1489792973092_101014"><br clear="none" id="yiv3951454861yui_3_16_0_ym19_1_1489792973092_101015"></div><div dir="ltr" id="yiv3951454861yui_3_16_0_ym19_1_1489792973092_101016"><span id="yiv3951454861yui_3_16_0_ym19_1_1489792973092_101017">Chris</span></div><div dir="ltr" id="yiv3951454861yui_3_16_0_ym19_1_1489792973092_101016"><span><br clear="none"></span></div> <div class="yiv3951454861qtdSeparateBR"><br clear="none"><br clear="none"></div><div class="yiv3951454861yqt1338129593" id="yiv3951454861yqt04298"><div class="yiv3951454861yahoo_quoted" style="display:block;"> <div style="font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px;"> <div style="font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px;"> <div dir="ltr"><font size="2" face="Arial"> On Monday, March 20, 2017 1:20 PM, Hal Finkel <hfinkel@anl.gov> wrote:<br clear="none"></font></div>  <br clear="none"><br clear="none"> <div class="yiv3951454861y_msg_container"><div dir="ltr"><br clear="none">On 03/20/2017 11:27 AM, Chris Chrulski via llvm-dev wrote:<br clear="none">> Hi,<br clear="none">><br clear="none">> I came across an issue where some optimizations that would normally be applied to standard math function calls are not getting applied when the –ffast-math option is enabled on the Clang command line on a Linux x86_64 target.<br clear="none">><br clear="none">> I tracked down the issue to occurring because the –ffast-math option is triggering Clang to preprocess the math.h header file with the __FINITE_MATH_ONLY__ macro set to 1. In this case, the Linux header files are redirecting several math functions using the __asm__ extension to rename the symbol. An example of what the header files contains is:<br clear="none">>        extern double exp (double) __asm__ ("" "__exp_finite") __attribute__ ((__nothrow__ ));<br clear="none">><br clear="none">> In effect, ‘exp’ gets converted to be ‘__exp_finite’ in the IR. Because some of the optimizations like constant folding or vectorization are looking for the original function name, those optimizations do not get triggered under –ffast-math due to these alternative function names.<br clear="none">><br clear="none">> Other affected functions include: acos, asin, exp2, log, log2, log10, and a few others.<br clear="none">><br clear="none">> Anybody know if this is intentional, or have input regarding whether these optimizations should be extended to also look for the renamed versions of these functions?<br clear="none"><br clear="none">It is not intentional; the optimizations should be extended. I imagine <br clear="none">that we would extend TargetLibraryInfo to have names for these <br clear="none">functions, and then we could recognize them when available, and generate <br clear="none">them when available and the inputs have the 'fast' tag.<br clear="none"><br clear="none">  -Hal<div class="yiv3951454861yqt3589688637" id="yiv3951454861yqtfd54928"><br clear="none"><br clear="none">><br clear="none">> Thanks,<br clear="none">> Chris<br clear="none">><br clear="none">><br clear="none">><br clear="none">> A couple of example cases:<br clear="none">><br clear="none">> // File: test_folding.c<br clear="none">><br clear="none">> // Constant fold will occur with:<br clear="none">> // clang -O2 -S -emit-llvm test_folding.c<br clear="none">><br clear="none">> // Constant fold will not occur with:<br clear="none">> // clang -O2 -S -emit-llvm -ffast-math test_folding.c<br clear="none">><br clear="none">> #include <math.h><br clear="none">><br clear="none">> double test_fold_exp() {<br clear="none">>    return exp(0.0);<br clear="none">> }<br clear="none">><br clear="none">> double test_fold_acos() {<br clear="none">>    return acos(1.0);<br clear="none">> }<br clear="none">><br clear="none">> ----------------------------------------------<br clear="none">><br clear="none">> // File: test_vectorize.c<br clear="none">><br clear="none">> // Vectorization will occur with:<br clear="none">> // clang -O2 -S -emit-llvm -fno-math-errno test_vectorize.c<br clear="none">><br clear="none">> // Vectorization will not occur with:<br clear="none">> // clang -O2 -S -emit-llvm -fno-math-errno -ffast-math test_vectorize.c<br clear="none">><br clear="none">> #include <math.h><br clear="none">><br clear="none">> void test_vectorize_exp(long n,  float* restrict y,  float* restrict x) {<br clear="none">>    long i;<br clear="none">>    for (i = 0; i < n; i++) {<br clear="none">>      x[i] = expf(y[i]);<br clear="none">>    }<br clear="none">> }<br clear="none">> _______________________________________________<br clear="none">> LLVM Developers mailing list<br clear="none">> <a rel="nofollow" shape="rect" ymailto="mailto:llvm-dev@lists.llvm.org" target="_blank" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br clear="none">> <a rel="nofollow" shape="rect" target="_blank" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a></div><br clear="none"><br clear="none">-- <br clear="none">Hal Finkel<br clear="none">Lead, Compiler Technology and Programming Languages<br clear="none">Leadership Computing Facility<br clear="none">Argonne National Laboratory<div class="yiv3951454861yqt3589688637" id="yiv3951454861yqtfd42118"><br clear="none"><br clear="none"></div></div><br clear="none"><br clear="none"></div>  </div> </div>  </div></div></div></div></div><div class="yqt1338129593" id="yqt30278">_______________________________________________<br clear="none">LLVM Developers mailing list<br clear="none"><a shape="rect" ymailto="mailto:llvm-dev@lists.llvm.org" href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br clear="none"><a shape="rect" href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br clear="none"></div><br><br></div>  </div> </div>  </div></div></body></html>