pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andres Freund <andres@anarazel.de>
Cc: pgsql-hackers@postgreSQL.org
Subject: Minor codegen silliness in ExecInterpExpr()
Date: Thu, 28 Sep 2017 16:21:34 -0400
Message-ID: <2508.1506630094@sss.pgh.pa.us> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>

I noticed the following while poking around with perf:

       |                             fcinfo->isnull = false;
       |b5b:   movb   $0x0,0x1c(%rdx)
       |                             *op->resvalue = op->d.func.fn_addr(fcinfo);
  0.02 |       mov    0x8(%rbx),%rcx
  1.19 |       mov    %rdx,%rdi
  0.93 |       mov    %rdx,(%rsp)
       |       mov    %rcx,0x8(%rsp)
  0.01 |       callq  *0x28(%rbx)
  2.17 |       mov    0x8(%rsp),%rcx
       |       mov    %rax,(%rcx)
       |                             *op->resnull = fcinfo->isnull;
  1.18 |       mov    (%rsp),%rdx
  4.32 |       mov    0x10(%rbx),%rax
  0.06 |       movzbl 0x1c(%rdx),%edx
  9.14 |       mov    %dl,(%rax)

It looks to me like gcc believes it is required to evaluate "op->resvalue"
before invoking the called function, just in case the function somehow has
access to *op and modifies that.  We could save a pointless register spill
and reload if there were a temporary variable in there, ie

		EEO_CASE(EEOP_FUNCEXPR)
		{
			FunctionCallInfo fcinfo = op->d.func.fcinfo_data;
+			Datum	fvalue;
	
			fcinfo->isnull = false;
-			*op->resvalue = op->d.func.fn_addr(fcinfo);
+			fvalue = op->d.func.fn_addr(fcinfo);
+			*op->resvalue = fvalue;
			*op->resnull = fcinfo->isnull;

			EEO_NEXT();
		}

and likewise in the other FUNCEXPR cases.

This is on a rather old gcc, haven't checked on bleeding-edge versions.

			regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



view thread (7+ messages)  latest in thread

Message-ID: <2508.1506630094@sss.pgh.pa.us>
Permalink:  ../2508.1506630094@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/2508.1506630094@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, andres@anarazel.de
  Subject: Re: Minor codegen silliness in ExecInterpExpr()
  In-Reply-To: <2508.1506630094@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox