[llvm-commits] turn on function merging

Nick Lewycky nicholas at mxc.ca
Sun Jul 11 00:12:03 PDT 2010


I'd like to turn on the function merging pass by default (patch 
attached). Function merging is already in the tree and I've been testing 
it locally for a while. It works great and doesn't do undue harm to my 
build times.

Functions are merged when they are identical under a comparison that 
treats all pointers as equivalent. So i8* and i32* are considered 
equivalent types, so long as you never load one which would produce an 
i8 as that's different from i32.

First of all, function merging is good because it produces smaller 
binaries. Doing it in the IR (say, instead of the linker) also saves us 
the compile time of emitting duplicate functions. When we can't remove a 
function mergefuncs leaves a tail-call stub and updates all callers to a 
canonical choice, improving the instruction cache hit rate.

The bad side is that the process is inherently O(n^2). We do a pair-wise 
comparison of functions, but in practise the comparisons fail quickly on 
mismatch, and the number of comparisons is small due to a good hash 
function. The hash is all the O(1) properties of the function (types, 
calling convention, etc.) plus the number of basic blocks which is O(n) 
but fast.

Also, it introduces new bitcasts, especially on function calls. This can 
break call graphs, alias analysis, etc. Because of this, I added 
function merging as the very last pass of the LTO chain.

Please comment whether you think this is a good or bad idea, or if 
you're testing the patch yourself prior to me committing it. Thanks!

Nick
-------------- next part --------------
A non-text attachment was scrubbed...
Name: turn-on-mergefuncs.patch
Type: text/x-patch
Size: 1842 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20100711/0dde4c85/attachment.bin>


More information about the llvm-commits mailing list