Inlining non-virtual thunks causes code bloat
| 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'.
Inlining into the thunk, in -O2, is actually consistent with GCC. The only difference remains -O0.
The optimizer's allowed to make that decision; we don't want to categorically disallow inlining into the thunk.
I only see the small thunk for -O1. For -O2 -Os the code is duplicated.
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.
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.
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?
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.
Ok, then this sounds like a frontend bug then :)
The frontend is emitting this with delegation.
John, I thought we were just inlining variadic thunks in the frontend. Is this an optimizer or frontend issue?