<div dir="ltr"><div><div>Hi Martin,<br><br></div>I believe Mehdi was referring to C11 subclause 7.12.1 paragraph 7:<br></div><div>If no such error occurs, <span style="font-family:monospace,monospace">errno</span> shall be left unmodified regardless of the setting of <span style="font-family:monospace,monospace">math_errhandling</span>.<br></div><div><br></div><div>Thus we are left with a question as to why a call with the constant is needs to be preserved when <span style="font-family:monospace,monospace">errno</span> is specified not to change by C11.<br></div><div><br></div>-- HT<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 20, 2016 at 7:12 AM, Martin J. O'Riordan via llvm-dev <span dir="ltr"><<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div link="blue" vlink="purple" lang="EN-IE"><div><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#1f497d">Hi Mehdi,<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#1f497d">The ISO C specification does permit the math functions to modify ‘</span><span style="font-family:"Courier New";color:black">errno</span><span style="font-family:"Book Antiqua",serif;color:#1f497d">’, but I thought that the ‘</span><span style="font-family:"Courier New";color:black">-fno-math-errno</span><span style="font-family:"Book Antiqua",serif;color:#1f497d">’ option was to tell the optimiser to assume that ‘</span><span style="font-family:"Courier New";color:black">errno</span><span style="font-family:"Book Antiqua",serif;color:#1f497d">’ is not modified by the math functions. Explicitly providing ‘</span><span style="font-family:"Courier New";color:black">-fno-math-errno</span><span style="font-family:"Book Antiqua",serif;color:#1f497d">’ is not restoring the elision optimisation that was performed by LLVM v3.8, and this is really only a driver option, with ‘</span><span style="font-family:"Courier New";color:black">-fmath-errno</span><span style="font-family:"Book Antiqua",serif;color:#1f497d">’ passed onto CC1 if ‘</span><span style="font-family:"Courier New";color:black">MathErrno</span><span style="font-family:"Book Antiqua",serif;color:#1f497d">’ is true, and omitted if false.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#1f497d">I certainly agree that if ‘</span><span style="font-family:"Courier New";color:black">MathErrno</span><span style="font-family:"Book Antiqua",serif;color:#1f497d">’ is true, then the compiler should not elide the call as it has to assume that there are memory write side-effects. It already models the math functions as built-ins and determine the expected answer when the arguments are constants, and elides the tests in the simple example below - all this is good, and when I use ‘</span><span style="font-family:"Courier New";color:black">-fno-builtin</span><span style="font-family:"Book Antiqua",serif;color:#1f497d">’ it stops correctly disabled this optimisation.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#1f497d">I modified my sources to force ‘</span><span style="font-family:"Courier New";color:black">readnone</span><span style="font-family:"Book Antiqua",serif;color:#1f497d">’ and even tried ‘</span><span style="font-family:"Courier New";color:black">setDoesNotAccessMemory()</span><span style="font-family:"Book Antiqua",serif;color:#1f497d">’ on the math functions, but this still results in one call occurring and the code generated is effectively:<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:"Courier New";color:black">(void)exp(1.0);<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-family:"Courier New";color:black">return 0;<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#1f497d">This is better, but still not as optimal as it was in v3.8. With this change, compiling with ‘</span><span style="font-family:"Courier New";color:black">-fmath-errno</span><span style="font-family:"Book Antiqua",serif;color:#1f497d">’ reverts to inserting two calls.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#1f497d">While calling these functions with constants is not terribly common in C code (mostly contrived test cases), it is a lot more common in real C++ code via template expansions and inlining. With ‘</span><span style="font-family:"Courier New";color:black">-O3 -S -emit-llvm -fno-math-errno</span><span style="font-family:"Book Antiqua",serif;color:#1f497d">’ plus my change to call ‘</span><span style="font-family:"Courier New";color:black">setDoesNotAccessMemory()</span><span style="font-family:"Book Antiqua",serif;color:#1f497d">’, the IR generated is as follows:<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">; ModuleID = 'src/mathElisions.c'<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">source_filename = "src/mathElisions.c"<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">target datalayout = "e-m:e-p:32:32-f64:64-i64:64-<wbr>v128:64-v64:64-v32:32-v16:16-<wbr>n8:16:32-S64"<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">target triple = "shave"<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"><u></u> <u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">; Function Attrs: nounwind readnone<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">define i32 @useMathName() local_unnamed_addr #0 {<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"> %1 = tail call float @exp(float 1.000000e+00)<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"> ret i32 0<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">}<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"><u></u> <u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">; Function Attrs: readnone<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">declare float @exp(float) local_unnamed_addr #1<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"><u></u> <u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">; Function Attrs: nounwind<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">define i32 @useOtherName() local_unnamed_addr #2 {<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"> %1 = tail call float @foo(float 1.000000e+00) #4<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"> %2 = fcmp olt float %1, 0x4005AE1480000000<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"> br i1 %2, label %7, label %3<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"><u></u> <u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">; <label>:3: <wbr> ; preds = %0<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"> %4 = tail call float @foo(float 1.000000e+00) #4<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"> %5 = fcmp ogt float %4, 0x4005C28F60000000<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"> br i1 %5, label %7, label %6<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"><u></u> <u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">; <label>:6: <wbr> ; preds = %3<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"> br label %7<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"><u></u> <u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">; <label>:7: <wbr> ; preds = %0, %3, %6<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"> %8 = phi i32 [ 0, %6 ], [ -1, %3 ], [ -1, %0 ]<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"> ret i32 %8<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">}<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"><u></u> <u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">declare float @foo(float) local_unnamed_addr #3<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black"><u></u> <u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">attributes #0 = { nounwind readnone "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-<wbr>leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="<wbr>false" "stack-protector-buffer-size"=<wbr>"8" "target-cpu"="myriad2.2" "unsafe-fp-math"="false" "use-soft-float"="false" }<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">attributes #1 = { readnone "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-<wbr>leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="<wbr>false" "stack-protector-buffer-size"=<wbr>"8" "target-cpu"="myriad2.2" "unsafe-fp-math"="false" "use-soft-float"="false" }<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">attributes #2 = { nounwind "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-<wbr>leaf" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="<wbr>false" "stack-protector-buffer-size"=<wbr>"8" "target-cpu"="myriad2.2" "unsafe-fp-math"="false" "use-soft-float"="false" }<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">attributes #3 = { "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-<wbr>leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="<wbr>false" "stack-protector-buffer-size"=<wbr>"8" "target-cpu"="myriad2.2" "unsafe-fp-math"="false" "use-soft-float"="false" }<u></u><u></u></span></p><p class="MsoNormal" style="margin-left:36.0pt"><span style="font-size:10.0pt;font-family:"Courier New";color:black">attributes #4 = { nounwind }<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#1f497d">Our implementation has C ‘</span><span style="font-family:"Courier New";color:black">float</span><span style="font-family:"Book Antiqua",serif;color:#1f497d">’ and ‘</span><span style="font-family:"Courier New";color:black">double</span><span style="font-family:"Book Antiqua",serif;color:#1f497d">’ as 32-bit IEEE Single-Precision and ‘</span><span style="font-family:"Courier New";color:black">long double</span><span style="font-family:"Book Antiqua",serif;color:#1f497d">’ as 64-bit IEEE Double-Precision.<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#1f497d">Thanks,<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#1f497d"><u></u> <u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#1f497d"> MartinO<u></u><u></u></span></p><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif;color:#1f497d"><u></u> <u></u></span></p><div><div style="border:none;border-top:solid #e1e1e1 1.0pt;padding:3.0pt 0cm 0cm 0cm"><p class="MsoNormal"><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" lang="EN-US">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif" lang="EN-US"> <a href="mailto:mehdi.amini@apple.com" target="_blank">mehdi.amini@apple.com</a> [<a href="mailto:mehdi.amini@apple.com" target="_blank">mailto:mehdi.amini@apple.com</a>] <br><b>Sent:</b> 16 September 2016 21:16<br><br><u></u><u></u></span></p></div></div><p class="MsoNormal"><u></u> <u></u></p><div><span class=""><blockquote style="margin-top:5.0pt;margin-bottom:5.0pt"><div><p class="MsoNormal">On Sep 16, 2016, at 1:30 AM, Martin J. O'Riordan via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<u></u><u></u></p></div><p class="MsoNormal"><u></u> <u></u></p><div><div><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif" lang="EN-GB">A little while ago I asked a question on CFE-Dev about a change in the behaviour of programs using the ISO C math functions, although that question should have been put to LLVM-Dev. But I got excellent clarification of the problem anyway. However, since then I have been trying to adapt our out-of-tree implementation to get the previous behaviour. The problem is that something like:</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div><div><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif" lang="EN-GB"> </span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div><div style="margin-left:36.0pt"><p class="MsoNormal"><span style="font-family:"Courier New"">#include <math.h></span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div><div style="margin-left:36.0pt"><p class="MsoNormal"><span style="font-family:"Courier New""> </span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div><div style="margin-left:36.0pt"><p class="MsoNormal"><span style="font-family:"Courier New"">extern double foo(double);</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div><div style="margin-left:36.0pt"><p class="MsoNormal"><span style="font-family:"Courier New""> </span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div><div style="margin-left:36.0pt"><p class="MsoNormal"><span style="font-family:"Courier New"">int useMathName() {</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div><div style="margin-left:36.0pt"><p class="MsoNormal"><span style="font-family:"Courier New""> if ((exp(1.0) < 2.71) || (exp(1.0) > 2.72))</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div><div style="margin-left:36.0pt"><p class="MsoNormal"><span style="font-family:"Courier New""> return -1;</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div><div style="margin-left:36.0pt"><p class="MsoNormal"><span style="font-family:"Courier New""> return 0;</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div><div style="margin-left:36.0pt"><p class="MsoNormal"><span style="font-family:"Courier New"">}</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div><div style="margin-left:36.0pt"><p class="MsoNormal"><span style="font-family:"Courier New""> </span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div><div style="margin-left:36.0pt"><p class="MsoNormal"><span style="font-family:"Courier New"">int useOtherName() {</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div><div style="margin-left:36.0pt"><p class="MsoNormal"><span style="font-family:"Courier New""> if ((foo(1.0) < 2.71) || (foo(1.0) > 2.72))</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div><div style="margin-left:36.0pt"><p class="MsoNormal"><span style="font-family:"Courier New""> return -1;</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div><div style="margin-left:36.0pt"><p class="MsoNormal"><span style="font-family:"Courier New""> return 0;</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div><div style="margin-left:36.0pt"><p class="MsoNormal"><span style="font-family:"Courier New"">}</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div><div><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif" lang="EN-GB"> </span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div><div><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif" lang="EN-GB">With v3.8.0 the compiler elided both the calls to ‘</span><span style="font-family:"Courier New"" lang="EN-GB">exp</span><span style="font-family:"Book Antiqua",serif" lang="EN-GB">’ and the tests, so the function ‘</span><span style="font-family:"Courier New"" lang="EN-GB">useMathName</span><span style="font-family:"Book Antiqua",serif" lang="EN-GB">’ reduced to simply:</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div><div><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif" lang="EN-GB"> </span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div><div style="margin-left:36.0pt"><p class="MsoNormal"><span style="font-family:"Courier New"" lang="EN-GB">return 0;</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div><div><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif" lang="EN-GB"> </span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div><div><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif" lang="EN-GB">But this was not correct as it ignored the possibility that the math functions could have the side-effect of changing ‘</span><span style="font-family:"Courier New"" lang="EN-GB">errno</span><span style="font-family:"Book Antiqua",serif" lang="EN-GB">’, and this was fixed in v3.9.0, and the calls are no longer elided, though using the “as-if” rule, the tests are still eliminated and ‘</span><span style="font-family:"Courier New"" lang="EN-GB">useMathName</span><span style="font-family:"Book Antiqua",serif" lang="EN-GB">’ becomes:</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div><div><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif" lang="EN-GB"> </span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div><div style="margin-left:36.0pt"><p class="MsoNormal"><span style="font-family:"Courier New"" lang="EN-GB">(void)exp(1.0);</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div><div style="margin-left:36.0pt"><p class="MsoNormal"><span style="font-family:"Courier New"" lang="EN-GB">(void)exp(1.0);</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div></div></blockquote><div><p class="MsoNormal"><u></u> <u></u></p></div></span><div><p class="MsoNormal">o me: isn’t the spec saying that errno shall be set on underflow and overflow. The constant folding should be able to detect this and fold if it does not happen?<u></u><u></u></p></div><span class=""><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">Also, because we don’t really model errno, we don’t constant fold these call anymore :(<u></u><u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p></div><blockquote style="margin-top:5.0pt;margin-bottom:5.0pt"><div><div style="margin-left:36.0pt"><p class="MsoNormal"><span style="font-family:"Courier New"" lang="EN-GB">return 0;</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div><div><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif" lang="EN-GB"> </span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div><div><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif" lang="EN-GB">So I changed our implementation so that ‘</span><span style="font-family:"Courier New"" lang="EN-GB">-fno-math-errno</span><span style="font-family:"Book Antiqua",serif" lang="EN-GB">’ is the default for the tool-chain, and the ‘</span><span style="font-family:"Courier New"" lang="EN-GB">-fmath-errno</span><span style="font-family:"Book Antiqua",serif" lang="EN-GB">’ option is not passed on to the CC1 phase. I expected that this would allow the compiler to elide the calls, but it is not doing so. I don’t want to use ‘</span><span style="font-family:"Courier New"" lang="EN-GB">-ffast-math</span><span style="font-family:"Book Antiqua",serif" lang="EN-GB">’ as this has lots of FP issues, and I don’t want to make it the default.</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div><div><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif" lang="EN-GB"> </span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div><div><p class="MsoNormal"><span style="font-family:"Book Antiqua",serif" lang="EN-GB">Any idea why the math functions are not elided? I am using ‘</span><span style="font-family:"Courier New"" lang="EN-GB">-O3</span><span style="font-family:"Book Antiqua",serif" lang="EN-GB">’ and implying ‘</span><span style="font-family:"Courier New"" lang="EN-GB">-fno-math-errno</span><span style="font-family:"Book Antiqua",serif" lang="EN-GB">’. I have verified that our Toolchain implements ‘</span><span style="font-family:"Courier New"" lang="EN-GB">IsMathErrnoDefault</span><span style="font-family:"Book Antiqua",serif" lang="EN-GB">’ and returns ‘</span><span style="font-family:"Courier New"" lang="EN-GB">false</span><span style="font-family:"Book Antiqua",serif" lang="EN-GB">’, and that the option ‘</span><span style="font-family:"Courier New"" lang="EN-GB">-fmath-errno</span><span style="font-family:"Book Antiqua",serif" lang="EN-GB">’ is not being passed to the CC1 stage. Since our math function implementation does not in fact change ‘</span><span style="font-family:"Courier New"" lang="EN-GB">errno</span><span style="font-family:"Book Antiqua",serif" lang="EN-GB">’, it is very desirable that this elision occurs in an FP safe way.</span><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"><u></u><u></u></span></p></div></div></blockquote><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">You can check that clang when emitting the IR is adding the attribute "readnone” on the declaration of exp(). If it does not then it assumes errno.<u></u><u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">As a starting point, have you tried to pass -fno-math-errno?<u></u><u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p></div><div><p class="MsoNormal">— <u></u><u></u></p></div><div><p class="MsoNormal">Mehdi<u></u><u></u></p></div><div><p class="MsoNormal"><u></u> <u></u></p></div></span></div></div></div><br>______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br></blockquote></div><br></div>