[LTO] Fix C++ thunks

Mark Mitchell mark@codesourcery.com
Wed Dec 17 22:28:00 GMT 2008


Chris Lattner wrote:

>> 1. Although we've never implemented it, one of the ideas with thunks was
>> that you could fall through into the main function body, rather than
>> jump to it.  That avoids a costly, often mis-predicted branch.  So, we
>> shouldn't do anything that makes that harder.
> 
> When are these branches expensive?  My understanding is that all
> reasonable desktop hardware (at least) has "perfect" prediction for
> unconditional branches.

Three reasons:

1. non-desktop hardware

2. even perfectly predicted branches are not free

3. thunks are generally the target of indirect jumps through a vtable,
so you have a sequence like "load memory to register", "indirect jump
through register", "add constant to register", "jump".  There's a lot of
hardware that doesn't do a great job with predicting all of that; if you
don't work out the target of the indirect jump, you don't have time to
load the target of the final jump before you hit it.

-- 
Mark Mitchell
CodeSourcery
mark@codesourcery.com
(650) 331-3385 x713



More information about the Gcc-patches mailing list