Hi,
Ideally we should have all changes for LLVM 22 in our February minor
releases. I have written up some notes on release synchronisation on
the wiki[1] to show the scheduling problem if we don't. The second
patch here still needs some validation.
1. We won't need our local llvm::backport::SectionMemoryManager for
LLVM 22, so it will be nice to draw a line under that messy business.
See commit message for details.
You can review the differences between our in-tree copy and the code
that was finally committed and will shortly ship in LLVM 22 like this:
LLVM_BRANCH=main
LLVM_URL=https://raw.githubusercontent.com/llvm/llvm-project/refs/heads
curl -s \
$LLVM_URL/$LLVM_BRANCH/llvm/include/llvm/ExecutionEngine/SectionMemoryManager.h
| \
diff -u - src/include/jit/SectionMemoryManager.h
curl -s \
$LLVM_URL/$LLVM_BRANCH/llvm/lib/ExecutionEngine/SectionMemoryManager.cpp | \
diff -u - src/backend/jit/llvm/SectionMemoryManager.cpp
In a week or two, LLVM_BRANCH=release/22.x should work too. I've
attached the output, which shows the expected changes in our copy,
namely:
* top-of-file comments
* namespace change
* tweaks for older LLVM versions
* tree-wide spellchecks and #include "" -> <> changes
They haven't made any changes on their side, except for adding some
LLVM_ABI macros added in LLVM 20 that we missed. See commit message
for why we don't want those.
The place in llvmjit_backport.h that does:
-#if defined(__aarch64__)
+#if defined(__aarch64__) && LLVM_VERSION_MAJOR < 22
#define USE_LLVM_BACKPORT_SECTION_MEMORY_MANAGER
... would be like this in REL_17_STABLE and earlier:
+#if defined(__aarch64__) && LLVM_VERSION_MAJOR > 11 && LLVM_VERSION_MAJOR < 22
That's because we never made the backport work with LLVM < 12, and I
have heard no complaints about that so at this point it looks like we
got away with it.
2. LLVM 22 changed the semantics of the "lifetime.end" instruction.
See commit message for references. Without this change, LLVM main/22
assertions fail in the regression tests with messages like this in
postmaster.log:
Intrinsic has incorrect argument type!
ptr @llvm.lifetime.end.p0
Intrinsic has incorrect argument type!
ptr @llvm.lifetime.end.p0
2026-01-02 17:28:31.394 NZDT client backend[42798] pg_regress/boolean
FATAL: fatal llvm error: Broken module found, compilation aborted!
I haven't seen anything bad happen in non-assertion builds.
Here's a potential minimal fix. I haven't yet proven that the
optimisation is still working as expected. Probably need to compile
an expression that calls an inlined function and then a non-inlined
function with jit_dump_bitcode=true, then find the right XXX.bc file
under pgdata, llvm-dis XXX.bc, llc XXX.ll, then visually inspect XXX.s
with enough caffeine to confirm that it's not spilling something (ie
store instructions) where previously it didn't, but I wanted to post
what I had so far to see if anyone has a better idea or an easy way to
test it...
[1] https://wiki.postgresql.org/wiki/LLVM#Cadence