<html><head></head><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px"><div id="yui_3_16_0_ym19_1_1489792973092_101008"><span id="yui_3_16_0_ym19_1_1489792973092_101009">Thanks Hal,</span></div><div id="yui_3_16_0_ym19_1_1489792973092_101010"><br id="yui_3_16_0_ym19_1_1489792973092_101011"></div><div dir="ltr" id="yui_3_16_0_ym19_1_1489792973092_101012"><span id="yui_3_16_0_ym19_1_1489792973092_101013">I'll take a look into extending the TargetLibraryInfo.</span></div><div dir="ltr" id="yui_3_16_0_ym19_1_1489792973092_101014"><br id="yui_3_16_0_ym19_1_1489792973092_101015"></div><div dir="ltr" id="yui_3_16_0_ym19_1_1489792973092_101016"><span id="yui_3_16_0_ym19_1_1489792973092_101017">Chris</span></div><div dir="ltr" id="yui_3_16_0_ym19_1_1489792973092_101016"><span><br></span></div> <div class="qtdSeparateBR"><br><br></div><div class="yahoo_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></font></div> <br><br> <div class="y_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="yqt3589688637" id="yqtfd54928"><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 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></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="yqt3589688637" id="yqtfd42118"><br clear="none"><br clear="none"></div></div><br><br></div> </div> </div> </div></div></body></html>