From 921fd7218df1d03f383de2ed1bed83e19077b6f4 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.
---
 src/backend/jit/llvm/llvmjit.c | 4 ++++
 1 file changed, 4 insertions(+)

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

