Using the following example program #include <math.h> double f(double d){ return sqrt(d); } and compiling it with "clang -O3 ...", I was trying to determine what it would take to get the X86 code generator to replace the call to sqrt with a sqrtsd instruction inline. It turns out that it could do exactly that, were it not for the fact that in the function visitUnaryFloatCall() at line 5514 in SelectionDAGBuilder.cpp, the result of !I.onlyReadsMemory() Is true, so the code is unable to replace the function call with an ISD::FSQRT SDNode. If I remove the above test, then the compiler will emit a sqrtsd instruction. I am hoping that someone might be able to comment on what onlyReadsMemory is supposed to do be doing in general and why it is returning false in this case. Thanks! Preston -- Preston Gurd <preston.gurd at intel.com> Intel Waterloo -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130517/051b48de/attachment.html>
On May 17, 2013, at 3:33 PM, "Gurd, Preston" <preston.gurd at intel.com> wrote:> Using the following example program > > #include <math.h> > > double f(double d){ > return sqrt(d); > } > > and compiling it with “clang –O3 …”, I was trying to determine what it would take to get the X86 code generator to replace the call to sqrt with a sqrtsd instruction inline. > > It turns out that it could do exactly that, were it not for the fact that in the function visitUnaryFloatCall() at line 5514 in SelectionDAGBuilder.cpp, the result of > > !I.onlyReadsMemory() > > Is true, so the code is unable to replace the function call with an ISD::FSQRT SDNode. If I remove the above test, then the compiler will emit a sqrtsd instruction. > > I am hoping that someone might be able to comment on what onlyReadsMemory is supposed to do be doing in general and why it is returning false in this case. >The compiler is being conservative about errno (which sqrt in libm can set, but "sqrtss" doesn't). Try building with -fno-math-errno. -Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130517/2074c7c2/attachment.html>
If you want sqrtss to be used without fast-math you can generate sqrtss and a call to sqrtf if NaN is returned. This is how gcc appears to handle it. Paul From: <Gurd>, Preston <preston.gurd at intel.com<mailto:preston.gurd at intel.com>> Date: Friday, 17 May, 2013 6:33 PM To: "LLVMdev (LLVMdev at cs.uiuc.edu<mailto:LLVMdev at cs.uiuc.edu>)" <LLVMdev at cs.uiuc.edu<mailto:LLVMdev at cs.uiuc.edu>> Subject: [LLVMdev] Inlining sqrt library function in X86 Using the following example program #include <math.h> double f(double d){ return sqrt(d); } and compiling it with “clang –O3 …”, I was trying to determine what it would take to get the X86 code generator to replace the call to sqrt with a sqrtsd instruction inline. It turns out that it could do exactly that, were it not for the fact that in the function visitUnaryFloatCall() at line 5514 in SelectionDAGBuilder.cpp, the result of !I.onlyReadsMemory() Is true, so the code is unable to replace the function call with an ISD::FSQRT SDNode. If I remove the above test, then the compiler will emit a sqrtsd instruction. I am hoping that someone might be able to comment on what onlyReadsMemory is supposed to do be doing in general and why it is returning false in this case. Thanks! Preston -- Preston Gurd <preston.gurd at intel.com<mailto:preston.gurd at intel.com>> Intel Waterloo
Does fast-math imply no-math-errno ? Thanks, Nadav On May 17, 2013, at 15:36, Chris Lattner <clattner at apple.com> wrote:> > On May 17, 2013, at 3:33 PM, "Gurd, Preston" <preston.gurd at intel.com> wrote: > >> Using the following example program >> >> #include <math.h> >> >> double f(double d){ >> return sqrt(d); >> } >> >> and compiling it with “clang –O3 …”, I was trying to determine what it would take to get the X86 code generator to replace the call to sqrt with a sqrtsd instruction inline. >> >> It turns out that it could do exactly that, were it not for the fact that in the function visitUnaryFloatCall() at line 5514 in SelectionDAGBuilder.cpp, the result of >> >> !I.onlyReadsMemory() >> >> Is true, so the code is unable to replace the function call with an ISD::FSQRT SDNode. If I remove the above test, then the compiler will emit a sqrtsd instruction. >> >> I am hoping that someone might be able to comment on what onlyReadsMemory is supposed to do be doing in general and why it is returning false in this case. > > The compiler is being conservative about errno (which sqrt in libm can set, but "sqrtss" doesn't). Try building with -fno-math-errno. > > -Chris > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130518/698f2d67/attachment.html>
Reasonably Related Threads
- [LLVMdev] Inlining sqrt library function in X86
- [LLVMdev] Inlining sqrt library function in X86
- [LLVMdev] Inlining sqrt library function in X86
- [LLVMdev] Problem with PostRASchedulerList.cpp - advice wanted
- [LLVMdev] How to locate the start if an address mode in an X86 MachineInstr?