[PATCH] Optimize call to sqrt.

Akira Hatanaka ahatanak at gmail.com
Tue Jun 18 12:51:40 PDT 2013


http://thread.gmane.org/gmane.comp.compilers.llvm.cvs/148393

Several people suggested the mips-specific sqrt optimization pass committed
in r183892 be moved to simplifylibcall, so here are my new patches.

- opt-sqrt-simplify-lib.patch
This patch moves the code that currently resides in Mips
OptimizeMathLibCalls.cpp 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.

- opt-sqrt-target-transform.patch
This patch adds a virtual function optimizeLibCall to TargetTransformInfo.
Targets should override this function if they wish to have the libcall
optimized.

- opt-sqrt-mips.patch
This patch adds class MipsTargetTransformInfo and overrides
function optimizeLibCall. I plan to delete MipsOptimizeMathLibCalls.cpp
once optimization is move to simplifylibcalls.


Two questions:
1. I wasn't sure if it was right to implement this optimization in
Scalar/SimplifyLibCalls.cpp,
since, according to the commit messages I read, Scalar/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?

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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130618/b82a49ad/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: opt-sqrt-simplify-lib.patch
Type: application/octet-stream
Size: 7948 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130618/b82a49ad/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: opt-sqrt-target-transform.patch
Type: application/octet-stream
Size: 1306 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130618/b82a49ad/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: opt-sqrt-mips.patch
Type: application/octet-stream
Size: 5000 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20130618/b82a49ad/attachment-0002.obj>


More information about the llvm-commits mailing list