<div dir="ltr"><div><div><a href="http://thread.gmane.org/gmane.comp.compilers.llvm.cvs/148393">http://thread.gmane.org/gmane.comp.compilers.llvm.cvs/148393</a><br></div></div><div><br></div>Several people suggested the mips-specific sqrt optimization pass committed in r183892 be moved to simplifylibcall, so here are my new patches.<div>
<br></div><div>- opt-sqrt-simplify-lib.patch</div><div>This patch moves the code that currently resides in Mips<span style="line-height:19px;text-align:justify">OptimizeMathLibCalls.cpp</span> to Scalar/SimplifyLibCalls.cpp. I was initially considering implementing this optimization in Utils/SimplifyLibCalls.cpp, but since the optimization in Utils/SimplifyLibCalls.cpp is run during instcombine and instcombine cannot handle optimization that changes the CFG, I decided to do this in Scalar/SimplifyLibCalls.cpp.  </div>
<div><br></div><div>- opt-sqrt-target-transform.patch</div><div>This patch adds a virtual function optimizeLibCall to TargetTransformInfo. Targets should override this function if they wish to have the libcall optimized. </div>
<div><br></div><div>- opt-sqrt-mips.patch</div><div>This patch adds class MipsTargetTransformInfo and overrides function optimizeLibCall. I plan to delete Mips<span style="line-height:19px;text-align:justify">OptimizeMathLibCalls.cpp once optimization is move to simplifylibcalls.</span></div>
<div><span style="line-height:19px;text-align:justify"><br></span></div><div style="text-align:justify"><span style="line-height:19px"><br></span></div><div style="text-align:justify"><span style="line-height:19px">Two questions:</span></div>
<div style="text-align:justify"><span style="line-height:19px">1. I wasn't sure if it was right to implement this optimization in </span>Scalar/SimplifyLibCalls.cpp, since, a<span style="line-height:19px">ccording to the commit messages I read, S</span>calar/SimplifyLibCalls.cpp was going to be removed once the migration to instcombine was complete. Are there any places other than Scalar/SimplifyLibCalls.cpp or Utils/SimplifyLibCalls.cpp that can implement this optimization?</div>
<div style="text-align:justify"><span style="line-height:19px"><br></span></div><div style="text-align:justify">2. Should I check whether the input is negative instead of checking whether the result of executing the native sqrt instruction is NaN? For mips, the latter approach was slightly faster (3-4%) for non-negative input, while the former was faster for negative input (10%), when I ran a simple test program. I think the difference will become smaller once we have a better scheduler for mips floating point instructions, so I am fine with either approach.</div>
<div style="text-align:justify"><br></div></div>