Re: LLVM 22

Поиск
Список
Период
Сортировка
От Matheus Alcantara
Тема Re: LLVM 22
Дата
Msg-id DFGZOTVPL100.Y09R8ROIHHTW@gmail.com
обсуждение исходный текст
Ответ на LLVM 22  (Thomas Munro <thomas.munro@gmail.com>)
Ответы Re: LLVM 22
Список pgsql-hackers
Hi,

On Fri Jan 2, 2026 at 11:02 PM -03, Thomas Munro wrote:
> 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've managed to reproduce this using LLVM 22.

> 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...
>
I'm not super familiar with reading assembly code but I tried my best to
inspect the LLVM 22 and LLVM 21 outputs and if I understood correctly I
think that 0002 is working as expected.

I've noticed a reduction on some instructions when using LLVM 22 with
the 0002 patch compared with LLVM 21. For example, here we needed less
instructions to set up the registers:

LLVM 22:
    LBB2_8:                                 ; %b.op.1.start
        mov    x20, #40824                     ; =0x9f78
        movk    x20, #19456, lsl #16
        movk    x20, #1, lsl #32
        ldr    x8, [x23]
        ldrb    w9, [x24]
        str    x8, [x20, #152]
        strb    w9, [x20, #160]

LLVM 21:
    LBB2_8:                                 ; %b.op.1.start
        mov    x25, #25352                     ; =0x6308
        movk    x25, #2946, lsl #16
        movk    x25, #1, lsl #32
        mov    x20, #23533                     ; =0x5bed
        movk    x20, #2946, lsl #16
        movk    x20, #1, lsl #32
        ldr    x8, [x23]
        ldrb    w9, [x24]
        stur    x8, [x25, #-248]
        sturb    w9, [x25, #-240]

I've also noticed that the generated assembly code for LLVM 22 use the
str and strb instructions instead of stur and sturb in some cases, which
according to IA is an improvement but unfortunately I did not find any
reference to prove this, sorry.

To test this I did the following steps:
set jit_above_cost = 0;
set jit_inline_above_cost = 0;
set jit_optimize_above_cost = 0;
set jit_dump_bitcode = true;

explain(analyze) select i % 2 = 0 OR i % 3 = 0 from generate_series(1, 100) i;

I'm attaching the .s files for the llvm 22 and for the llvm 21 outputs
that I used to inspect.

--
Matheus Alcantara
EDB: https://www.enterprisedb.com


Вложения

В списке pgsql-hackers по дате отправления: