From 84c3aa78af6df9b9f02139b46cc20739e3948ad8 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 | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/src/backend/jit/llvm/llvmjit.c b/src/backend/jit/llvm/llvmjit.c
index 8d009dd5cf7..2e8aa4749db 100644
--- a/src/backend/jit/llvm/llvmjit.c
+++ b/src/backend/jit/llvm/llvmjit.c
@@ -674,7 +674,11 @@ 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
+		/* default<O0> includes always-inline pass */
 		passes = "default<O0>,mem2reg";
 
 	options = LLVMCreatePassBuilderOptions();
-- 
2.51.0

