LLVM 22
Thomas Munro <thomas.munro@gmail.com>
From: Thomas Munro <thomas.munro@gmail.com>
To: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Date: 2026-01-03T02:02:37Z
Lists: pgsql-hackers
Attachments
- SectionMemoryManager-diff.txt (text/plain)
- 0001-jit-Skip-local-SectionMemoryManager-for-LLVM-22.patch (text/x-patch) patch 0001
- 0002-jit-API-changes-for-LLVM-22.patch (text/x-patch) patch 0002
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
Commits
-
jit: No backport::SectionMemoryManager for LLVM 22.
- 9b354cfc5584 14.23 landed
- 963fccc09cc6 15.18 landed
- 8354cd7ff575 16.14 landed
- 0a2291b59f9b 17.10 landed
- 5c54e0f48fa2 18.4 landed
- be21341e13d9 19 (unreleased) landed
-
jit: Stop emitting lifetime.end for LLVM 22.
- b4e7cd428c00 14.23 landed
- c00ea2b5b4f1 15.18 landed
- 26f27c592c5d 16.14 landed
- b6d0cddbe27d 17.10 landed
- 78cea19bf7da 18.4 landed
- de6b80e5ff4b 19 (unreleased) landed