Hi, While reviewing the llvm-22 patches[0], I've tried to trigger JIT inlining using the provided check_jit_code.sh script. The script generates bc for both jit_inline_above_cost=0 and jit_inline_above_cost=100000 and compares the generated code.
However, the generated bitcode were more or less the same, the only minor difference being the "inlining" version had additional strings. I've made sure to install through autoconf as meson doesn't generate and install bitcode files yet[1]. Debugging showed the code correctly going through llvm_inline and correctly importing the functions in the module. However, I'm using llvm21 and only the "default<O0>,mem2reg" passes are used, without any inlining passes. With llvm<17, the passes were configured as follow: - No optimisation and no inlining: always-inline - No optimisation and inlining: inline - Optimisation: O3 (which includes inline) The attached patch adds the inline pass when jit inlining is triggered without optimisation, as was done with LLVM<17. I didn't add the always-inline pass as I don't think this can have any effect. From what I understand, the functions need to be imported through llvm_inline for LLVM to be able to inline them. I've tested by tagging int4mod as always inline, and the generated bc was still calling the function despite the always-inline pass. Regards, Anthonin Bonnefoy [0]: https://www.postgresql.org/message-id/flat/CA%2BhUKGJTumad75o8Zao-LFseEbt%3DenbUFCM7LZVV%3Dc8yg2i7dg%40mail.gmail.com [1]: https://www.postgresql.org/message-id/flat/206b001d-1884-4081-bd02-bed5c92f02ba%40eisentraut.org
#!/bin/bash
set -eu
QUERY="select aid % 2 FROM pgbench_accounts limit 10;"
generate_s_file ()
{
pushd $PGDATA > /dev/null
bc_file=$(ls -tr | grep '0.optimized.bc' | tail -n1)
ll_file="$(basename $bc_file .bc).ll"
s_file="$(basename $bc_file .bc).s"
# Generate ll file
llvm-dis $bc_file
# Generate s file
llc $ll_file
popd > /dev/null
echo $PGDATA/$s_file
}
psql "options='-cjit_inline_above_cost=0 -cjit_above_cost=0 -cjit_dump_bitcode=true'" -c "$QUERY"
inline=$(generate_s_file)
psql "options='-cjit_inline_above_cost=100000 -cjit_above_cost=0 -cjit_dump_bitcode=true'" -c "$QUERY"
no_inline=$(generate_s_file)
vimdiff $inline $no_inline
v1-0001-Add-missing-JIT-inline-pass-for-llvm-17.patch
Description: Binary data
