llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

Inlining non-virtual thunks causes code bloat

Open jrmuizel opened this issue 15 years ago • 10 comments

Bugzilla Link 10373
Version trunk
OS All
CC @asl,@DougGregor,@ekatz,@rjmccall

Extended Description

The following example compiles to two separate functions:

class nsSVGElement { virtual void PrependLocalTransformTo() const; };

class nsIDOMSVGAnimatedPathData { virtual unsigned int GetPathSegList(void **aPathSegList) = 0; };

class nsSVGPathElement : public nsSVGElement, public nsIDOMSVGAnimatedPathData { public: unsigned int virtual GetPathSegList(void **aPathSegList); };

void *GetDOMWrapper(void *aList,void *aElement, bool aIsAnimValList); void *GetBaseValKey();

unsigned int nsSVGPathElement::GetPathSegList(void * *aPathSegList) { void *key = GetBaseValKey(); *aPathSegList = GetDOMWrapper(key, this, false); return *aPathSegList ? 0 : 0x8007000e; }

GCC compiles the thunk an 'add' and 'jmp'.

jrmuizel avatar Jul 15 '11 21:07 jrmuizel

Inlining into the thunk, in -O2, is actually consistent with GCC. The only difference remains -O0.

ekatz avatar Oct 29 '19 19:10 ekatz

The optimizer's allowed to make that decision; we don't want to categorically disallow inlining into the thunk.

rjmccall avatar Oct 29 '19 17:10 rjmccall

I only see the small thunk for -O1. For -O2 -Os the code is duplicated.

jrmuizel avatar Oct 29 '19 17:10 jrmuizel

So I think we could close this bug as fixed because it works in optimized builds, or we could leave it open as a request for the frontend to allow the backend to emit slimmer thunks at -O0.

rjmccall avatar Oct 29 '19 16:10 rjmccall

Clang isn't inlining the target at -O0, it's just emitting the thunk with more instructions than it could. That's probably in part because we're emitting allocas for the parameters; in general that's good for debugging, but we could avoid it in thunks without much loss.

rjmccall avatar Oct 29 '19 16:10 rjmccall

Still reproducible on clang 9.0 with -O0, but -O1 (and above) will produce the required optimized code (on GCC even, this code is optimized even on -O0).

Does this satisfy to close the issue?

ekatz avatar Oct 29 '19 08:10 ekatz

Chris, when I said "with delegation", I meant that the thunk function is just calling the main implementation. That's the code we want to see after optimization. I would classify this as an optimizer bug.

rjmccall avatar Jul 16 '11 20:07 rjmccall

Ok, then this sounds like a frontend bug then :)

lattner avatar Jul 16 '11 19:07 lattner

The frontend is emitting this with delegation.

rjmccall avatar Jul 15 '11 23:07 rjmccall

John, I thought we were just inlining variadic thunks in the frontend. Is this an optimizer or frontend issue?

lattner avatar Jul 15 '11 22:07 lattner