Let special __result variable be an alias for sret

So for functions using sret and featuring an out contract, we save an
additional alloca + memcpy by using the sret pointer as storage.
This commit is contained in:
Martin 2016-07-03 21:26:10 +02:00
parent 1760e261db
commit 12ff7ef803
2 changed files with 22 additions and 2 deletions

View file

@ -884,8 +884,9 @@ void DtoVarDeclaration(VarDeclaration *vd) {
if (isIrLocalCreated(vd)) {
// Nothing to do if it has already been allocated.
} else if (gIR->func()->sretArg && gIR->func()->decl->nrvo_can &&
gIR->func()->decl->nrvo_var == vd) {
} else if (gIR->func()->sretArg && ((gIR->func()->decl->nrvo_can &&
gIR->func()->decl->nrvo_var == vd) ||
vd->isResult())) {
// Named Return Value Optimization (NRVO):
// T f() {
// T ret; // &ret == hidden pointer