[cfe-dev] When two functions are the same could clang optimize out one of them?
John McCall
rjmccall at apple.com
Tue Mar 8 00:07:32 PST 2011
On Mar 7, 2011, at 9:55 PM, 邓尧 wrote:
> When the generated instructions of two functions "f()" & "g()" are the same(when templates are used it isn't unusual), could clang remove the function "f()" in the object file and translate "f()" calls to "g()" calls?
C and C++ require that almost all objects, including function objects, have different addresses. In principle, we can detect cases where a program doesn't rely on the address of a function; in other cases we can just emit one function as a tail call to the other. There's actually already an LLVM optimization that does something like this, although I believe it's not enabled by default because detecting the equivalence of functions is very difficult to do quickly.
John.
More information about the cfe-dev
mailing list