From 3967db1b1ad7eb51699651ef27996b177c331f5d Mon Sep 17 00:00:00 2001
From: Anthonin Bonnefoy <anthonin.bonnefoy@datadoghq.com>
Date: Tue, 13 Jan 2026 15:21:52 +0100
Subject: Add missing JIT inline pass for llvm>=17

With llvm >= 17, transform passes are provided as string to
LLVMRunPasses. Only two passes are used: "default<O3>" and
"default<O0>,mem2reg".

With previous LLVM versions, an additional inline pass was added when
JIT inlining was enabled without optimisation. With LLVM>=17, the code
will go through llvm_inline, prepare the functions for inlining, but
the generated bitcode will be the same due to the missing inline pass.

This patch restores the previous inline behaviour by adding an inline
pass when inline is enabled but no optimisation is done.

This fixes an oversigth introduced by 76200e5e when support for LLVM>=17
was added.
---
 src/backend/jit/llvm/llvmjit.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/backend/jit/llvm/llvmjit.c b/src/backend/jit/llvm/llvmjit.c
index 8d009dd5cf7..32b6125e812 100644
--- a/src/backend/jit/llvm/llvmjit.c
+++ b/src/backend/jit/llvm/llvmjit.c
@@ -674,6 +674,9 @@ llvm_optimize_module(LLVMJitContext *context, LLVMModuleRef module)
 
 	if (context->base.flags & PGJIT_OPT3)
 		passes = "default<O3>";
+	else if (context->base.flags & PGJIT_INLINE)
+		/* if doing inlining, but no expensive optimization, add inline pass */
+		passes = "default<O0>,mem2reg,inline";
 	else
 		passes = "default<O0>,mem2reg";
 
-- 
2.51.0

