Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vlGop-009RwE-0v for pgsql-hackers@arkaria.postgresql.org; Thu, 29 Jan 2026 01:27:36 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vlGoo-005Ggk-1F for pgsql-hackers@arkaria.postgresql.org; Thu, 29 Jan 2026 01:27:34 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vlGon-005GgP-1g for pgsql-hackers@lists.postgresql.org; Thu, 29 Jan 2026 01:27:34 +0000 Received: from fhigh-b3-smtp.messagingengine.com ([202.12.124.154]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vlGol-002ppz-0B for pgsql-hackers@lists.postgresql.org; Thu, 29 Jan 2026 01:27:32 +0000 Received: from phl-compute-03.internal (phl-compute-03.internal [10.202.2.43]) by mailfhigh.stl.internal (Postfix) with ESMTP id 9E42B7A00A4; Wed, 28 Jan 2026 20:27:30 -0500 (EST) Received: from phl-frontend-03 ([10.202.2.162]) by phl-compute-03.internal (MEProxy); Wed, 28 Jan 2026 20:27:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=anarazel.de; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm3; t=1769650050; x=1769736450; bh=D9K/FJKNnD xScAtCGnvu22HB/maSHKZUAlhe2Zxyde4=; b=MR8/fH8MZwQmShm4NMSaMe9DS1 ZRaK5HOY34xdW+kEsUnVfqlwnp4EBhOEa3KUcG0ESuea4V6WQB6TbrdyeAL1SnmK t2FPsjs3lgwoz930gfpxlie31KqNQ+xZaWpo5+kARMMVf5p/oJt7WhWkM4oFtF5r kpr09mhr7xLPsbtwnBctNZMr5TL+b3Ho97MMo2zFY9yW20DFDCsEZjLVJxMKWAUd WjfcDsFLEF/GEAlnfAWpogIl9x8NRjeBKAFCVU4VGh6UDdsqN58nfemFSVNQW/PU Pbv9QZqhHCzZxDU4zwULj+cmVAI2IvlMAV02nwI8K/kfdUIBJNg9BzPitunQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t= 1769650050; x=1769736450; bh=D9K/FJKNnDxScAtCGnvu22HB/maSHKZUAlh e2Zxyde4=; b=eQrPkhopiuE8HGwTpm4gbpahi2sYzbcUKPlpGHtYJvjJdX9iClf llW+ceBzZjit0xB+ADPY7pyRrkELh+KSvW8K1QyF/W1Ry+zDI1blHIutkSfeMWHe jM0jlg9ATj3/ZRVPOPU1N92KAy17DlgC0a+1Trh0fuM6MSVGVnpsfs+QoB3TTCHc Xm/Rnlwj0OOmbQn07qf0K8SRMYArKiDNXN387zgM9LYA4mStcX+0oOn8LPZWMRrL O0cbDmfj9aVTUJ8Sv0Nx/TO7C45hfIr52C9fKel8bx5HAhR/tE5vxCf2RfJX1rwL KquQrQL3kUON/+GX3gaqZwNlARsoQSFcB2A== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefgedrtddtgdduieegkeejucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepfffhvfevuffkfhggtggujgesmhdtsfertddtvdenucfhrhhomheptehnughrvghs ucfhrhgvuhhnugcuoegrnhgurhgvshesrghnrghrrgiivghlrdguvgeqnecuggftrfgrth htvghrnhepfeefudejgffghfegheduffduieejgedtkeejhfevieevgeekgeekleeljeef keeinecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprg hnughrvghssegrnhgrrhgriigvlhdruggvpdhnsggprhgtphhtthhopeegpdhmohguvgep shhmthhpohhuthdprhgtphhtthhopegrnhhthhhonhhinhdrsghonhhnvghfohihsegurg htrgguohhghhhqrdgtohhmpdhrtghpthhtohepmhgrthhhvghushhsshhilhhvleejsehg mhgrihhlrdgtohhmpdhrtghpthhtohepthhhohhmrghsrdhmuhhnrhhosehgmhgrihhlrd gtohhmpdhrtghpthhtohepphhgshhqlhdqhhgrtghkvghrsheslhhishhtshdrphhoshht ghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: id4a34324:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 28 Jan 2026 20:27:30 -0500 (EST) Date: Wed, 28 Jan 2026 20:27:29 -0500 From: Andres Freund To: Anthonin Bonnefoy Cc: Thomas Munro , PostgreSQL Hackers , Matheus Alcantara Subject: Re: LLVM 22 Message-ID: <5lusocererqcl4assiz6fbwvspjx422grxttzy46bnwicc3vwq@tzj22ll2daaw> References: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="ba542ub7gfwft3to" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --ba542ub7gfwft3to Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Hi, On 2026-01-14 17:12:45 +0100, Anthonin Bonnefoy wrote: > I've tried to generate multiple bitcode for a simple 'select aid % 2 > FROM pgbench_accounts limit 10;' query. To keep bitcode simple, I've > modified the passes to use "default,mem2reg,inline" when we have > JIT inline without optimization (as described in [0]). I've tried the > following > - LLVM21: With lifetime > - LLVM21: Without lifetime > - LLVM22: With Poison > - LLVM22: Without Poison > > In the 4 scenarios, the generated bc were the same with the exact same > instructions. Removing the lifetime end or the poison value doesn't > seem to change anything at this level of optimisation. > > I'm not sure how to interpret this. Maybe the test is incorrect and a > different function needs to be called to possibly trigger the issue? > Or the poison/lifetime is only useful when going through the O3 > optimisation pass? I think it's the latter - at -O0 there's nothing that could use the information. The goal of the lifetime annotations was to allow llvm to remove stores an loads of FunctionCallInfo->{args,isnull}. After we stored e.g. fcinfo->isnull before a function call and then checked it after the function call, we don't need it anymore. I think that can only matter when the called function is actually inlined, otherwise there's no way that LLVM can see the store is unnecessary. Unfortunately there's an issue with modern LLVM, regardless of lifetime or poison. Generally it's able to eliminate stores that are followed by a poison, but if there's a load inbetween, it fails. The odd part is that it *is* able to eliminate the load (by forwarding the stored value). It seems to be an ordering issue - instcombine is required to remove the load, but also removes the poison, which in turn is required for dead store elimination. Gngng. I've attached a reproducer. I'm not sure the llvm folks will be all that interested - there's no real C correspondance to this. And, as it turns out, if I feed the memory to something like free(), the analysis actually *does* figure out that it's not needed anymore. I think if / once we move most of this to a stack allocation, the problem would also vanish. Greetings, Andres Freund --ba542ub7gfwft3to Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="test.ll" ; ModuleID = '/tmp/test.c' source_filename = "/tmp/test.c" target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" target triple = "x86_64-unknown-linux-gnu" %struct.Arg = type { i8, i64 } define noundef i64 @evalexpr_broken(ptr %0) { entry: %isnullp = getelementptr %struct.Arg, ptr %0, i32 0 %arg0p = getelementptr %struct.Arg, ptr %0, i32 1 ; value that's needed just temporarily, during "operation" below store i8 38, ptr %isnullp %arg0 = load i64, ptr %arg0p ; operation that has been optimized out would be here, elided for brevity %isnull = load i8, ptr %isnullp ; signal that memory at %isnullp isn't needed anymore store i8 poison, ptr %isnullp ret i64 %arg0 } define noundef i64 @evalexpr_works(ptr %0) { entry: %isnullp = getelementptr %struct.Arg, ptr %0, i32 0 %arg0p = getelementptr %struct.Arg, ptr %0, i32 1 store i8 38, ptr %isnullp %arg0 = load i64, ptr %arg0p %isnull = load i8, ptr %isnullp store i8 poison, ptr %isnullp ; now that the return value isn't needed anymore, optimizer can optimize away ; the store to %isnullp ret i64 0 } --ba542ub7gfwft3to--