Re: LLVM 22

From: Thomas Munro <thomas(dot)munro(at)gmail(dot)com>
To: Andres Freund <andres(at)anarazel(dot)de>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Devrim Gündüz <devrim(at)gunduz(dot)org>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Matheus Alcantara <matheusssilv97(at)gmail(dot)com>, Anthonin Bonnefoy <anthonin(dot)bonnefoy(at)datadoghq(dot)com>
Subject: Re: LLVM 22
Date: 2026-04-03 03:04:13
Message-ID: CA+hUKG+skVJgFiqjxGo1E72rMULqSRs09PJc9sWKySpCvN8RKA@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Apr 3, 2026 at 3:31 AM Andres Freund <andres(at)anarazel(dot)de> wrote:
> > I see a few options, but I need to hack on them for a while to figure
> > out the tradeoffs, or what I'm missing... after the freeze.
>
> I've experimented a bunch with this, it seems we need the larger changes done
> as part of the patchset for removing pointers from the expressions to actually
> allow recent-ish LLVM to optimize this. I did verify that what we did didn't
> have an effect with any other recent LLVM either.

Yeah, I noticed this connection as well, coming at it from a keyhole
how-do-I-fix-THIS-problem angle. It seemed to me that where
ExecInitFunc() builds the code to compute argument values to push into
&fcinfo->args[argno].value (a palloc'd FunctionCallInfoData object),
it might first alloca the space and store the collid etc (and after
return, it could lifetime.end it, or maybe the eventual ret in the
caller is enough but I don't see any reason not to lifetime.end it
ASAP), and then the destination would become a pointer into that, and
the most natural thing would be a stack pointer-relative one, and then
you'd have removed a major source of non-cacheability of compiled
expressions. It took me a while to grok the function argument layout,
which is ... this might be a stretch... a bit like Fortran, neither a
linear stack nor a spaghetti stack, but just a bag of variables ready
to be used as functions arguments, with recursion not permitted. And
also to grok the quirks of our V1 calls that compelled you to do it
like that. But I'm still learning the secrets of this code and I may
be way off base in these musings, I haven't actually tried anything
and it sounds like I should keep out of your way...

> The real fix here might be to have a separate calling convention for the very
> common case of a scalar stable function with 1-3 arguments. We loose a fair
> bit of efficiency even in interpreted execution due to ferrying arguments,
> their nullness, and the nullness of the return value through memory.

Yeah. I understand much better why you say that now.
FunctionCallInfoData holds data with two different lifetimes, some of
which might not be needed.

In response to

  • Re: LLVM 22 at 2026-04-02 14:31:48 from Andres Freund

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas Munro 2026-04-03 03:06:35 Re: LLVM 22
Previous Message Lukas Fittl 2026-04-03 02:32:36 Re: Add custom EXPLAIN options support to auto_explain