> On Sat, Mar 30, 2024 at 04:38:11PM +1300, Thomas Munro wrote: > On Fri, Mar 22, 2024 at 7:15 AM Dmitry Dolgov <9erthali...@gmail.com> wrote: > > > For verification, I've modified the deform.outblock to call LLVMBuildRet > > > instead of LLVMBuildRetVoid and this seems to help -- inline and deform > > > stages are still performed as before, but nothing crashes. But of course > > > it doesn't sound right that inlining pass cannot process such code. > > Thanks for investigating and filing the issue. It doesn't seem to be > moving yet. Do you want to share the LLVMBuildRet() workaround? > Maybe we need to consider shipping something like that in the > meantime?
Yeah, sorry, I'm a bit baffled about this situation myself. Yesterday I've opened a one-line PR fix that should address the issue, maybe this would help. In the meantime I've attached what did work for me as a workaround -- it essentially just makes the deform function to return some value. It's ugly, but since call site will ignore that, and it's only one occasion where LLVMBuildRetVoid is used, maybe it's acceptable. Give me a moment, I'm going to test this change more (waiting on rebuilding LLVM, it takes quire a while on my machine :( ), then can confirm that it works as expected on the latest version.
>From 83e37220cc3e8cb04b0d8a608240fdde4b003713 Mon Sep 17 00:00:00 2001 From: Dmitrii Dolgov <9erthali...@gmail.com> Date: Sat, 30 Mar 2024 17:45:38 +0100 Subject: [PATCH v1] Workaround for deform crashing in LLVM inliner Deform function returns via the outblock that contains a "ret void" instruction build with LLVMBuildRetVoid. This triggers a bug in the latest LLVM 18.1, when the inliner pass is applied to the function [1]. Avoid the issue via introducing a fake return variable, which will be ignored on the call site. [1]: https://github.com/llvm/llvm-project/issues/86162 --- src/backend/jit/llvm/llvmjit_deform.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backend/jit/llvm/llvmjit_deform.c b/src/backend/jit/llvm/llvmjit_deform.c index b07f8e7f756..7ebc7b6d731 100644 --- a/src/backend/jit/llvm/llvmjit_deform.c +++ b/src/backend/jit/llvm/llvmjit_deform.c @@ -761,6 +761,7 @@ slot_compile_deform(LLVMJitContext *context, TupleDesc desc, { LLVMValueRef v_off = l_load(b, TypeSizeT, v_offp, ""); LLVMValueRef v_flags; + LLVMValueRef v_fake_ret = l_sizet_const(0); LLVMBuildStore(b, l_int16_const(lc, natts), v_nvalidp); v_off = LLVMBuildTrunc(b, v_off, LLVMInt32TypeInContext(lc), ""); @@ -768,7 +769,7 @@ slot_compile_deform(LLVMJitContext *context, TupleDesc desc, v_flags = l_load(b, LLVMInt16TypeInContext(lc), v_flagsp, "tts_flags"); v_flags = LLVMBuildOr(b, v_flags, l_int16_const(lc, TTS_FLAG_SLOW), ""); LLVMBuildStore(b, v_flags, v_flagsp); - LLVMBuildRetVoid(b); + LLVMBuildRet(b, v_fake_ret); } LLVMDisposeBuilder(b); base-commit: 7eb9a8201890f3b208fd4c109a5b08bf139b692a -- 2.41.0