Conditionally eliminate library calls where the result value is not used
authorRong Xu <xur@google.com>
Tue, 18 Oct 2016 21:36:27 +0000 (21:36 +0000)
committerRong Xu <xur@google.com>
Tue, 18 Oct 2016 21:36:27 +0000 (21:36 +0000)
commit1c0e9b97d2215e2855f2f97cd3db456e8e8dc1b7
treeda2b7412812181a5a61e6a569e787e0e4042aaa3
parentea62ae984414e737f62397fc025d908c7c740969
Conditionally eliminate library calls where the result value is not used

Summary:
This pass shrink-wraps a condition to some library calls where the call
result is not used. For example:
   sqrt(val);
 is transformed to
   if (val < 0)
     sqrt(val);
Even if the result of library call is not being used, the compiler cannot
safely delete the call because the function can set errno on error
conditions.
Note in many functions, the error condition solely depends on the incoming
parameter. In this optimization, we can generate the condition can lead to
the errno to shrink-wrap the call. Since the chances of hitting the error
condition is low, the runtime call is effectively eliminated.

These partially dead calls are usually results of C++ abstraction penalty
exposed by inlining. This optimization hits 108 times in 19 C/C++ programs
in SPEC2006.

Reviewers: hfinkel, mehdi_amini, davidxl

Subscribers: modocache, mgorny, mehdi_amini, xur, llvm-commits, beanz

Differential Revision: https://reviews.llvm.org/D24414

llvm-svn: 284542
13 files changed:
llvm/include/llvm/InitializePasses.h
llvm/include/llvm/LinkAllPasses.h
llvm/include/llvm/Transforms/Scalar.h
llvm/include/llvm/Transforms/Utils/LibCallsShrinkWrap.h [new file with mode: 0644]
llvm/lib/Passes/PassBuilder.cpp
llvm/lib/Passes/PassRegistry.def
llvm/lib/Transforms/IPO/PassManagerBuilder.cpp
llvm/lib/Transforms/Utils/CMakeLists.txt
llvm/lib/Transforms/Utils/LibCallsShrinkWrap.cpp [new file with mode: 0644]
llvm/lib/Transforms/Utils/Utils.cpp
llvm/test/Transforms/Util/libcalls-shrinkwrap-double.ll [new file with mode: 0644]
llvm/test/Transforms/Util/libcalls-shrinkwrap-float.ll [new file with mode: 0644]
llvm/test/Transforms/Util/libcalls-shrinkwrap-long-double.ll [new file with mode: 0644]