From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5BDEE3B4EAF for ; Wed, 15 Jul 2026 04:54:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784091294; cv=none; b=OviExOAvDO6SG+DtwtmMz0//DBwfJz/pzyPESNyLG6b3KQE/ZX3IuWhMeU5vR0HygsP+I3TsjNG5pIzppXXdV1xMtgxlBCbm4S37PY3hpG7qISf4mMinTzKYqZTjziJbnt3QVuZK95V8MUZ9l3Tc4iG7r8LQi4wDboCrROa3Ozo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784091294; c=relaxed/simple; bh=UZHkCvGmlFvM5JpW+Js+LY9s4HF5Ch3tJQlZO8RevN0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=soynlgDSltZcx7joGUQM5QB2JF4jtruZ7bus8BIqRq192JGVKxy88RA/xh+5JLNrUfZHPQ+O5+bPRgCPQInJQfYqAElXPb2PSljSXWTRwDK9DlTXsrEEX/lppqGi60ci0wkjjDXBuj/baIbR/iukl8Rvb2gAnGPUQxUgdQgwyOE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=K6y9sY3K; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="K6y9sY3K" Received: by smtp.kernel.org (Postfix) with ESMTPSA id A2A581F000E9; Wed, 15 Jul 2026 04:54:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1784091293; bh=szctrhXtrNfpxmxD7K7X+WL708R9WB4DHEO0SLLUggM=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=K6y9sY3KMqn1Bd3G7oVdi8h71NjQJPBxXF4NJIEb8EB6/MIVXfXbpMFCZXoX4snfs Vm2Z/G1fIEsCaNgX0Qd+5cj233I9gOudtQRmpbl8gSJLWnAxdZpqWPPBXTquFs7eL6 ZgJ5KHMb3ibZzu+s2zns1U5U1m7mbJPi7FJJDFNM= Date: Wed, 15 Jul 2026 06:54:46 +0200 From: Greg Kroah-Hartman To: Vincent Mailhol Cc: Andrew Morton , Rasmus Villemoes , Sakari Ailus , Nick Desaulniers , Alexander Lobakin , Arnd Bergmann , David Sterba , Ivo van Doorn , Alexey Dobriyan , linux-kernel@vger.kernel.org Subject: Re: [PATCH 0/3] container_of: refactors Message-ID: <2026071514-sulfur-skydiver-7604@gregkh> References: <20260714-containerof_refactor-v1-0-b5c31164d2ad@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260714-containerof_refactor-v1-0-b5c31164d2ad@kernel.org> On Tue, Jul 14, 2026 at 08:18:00PM +0200, Vincent Mailhol wrote: > This series refactors the container_of() function-like macro to improve > readability and remove a sparse/W=2 shadow warning. Further details in > each patch. > > While I was expecting this series to be boring and purely cosmetic, the > bloat-o-meter stats gave some unexpected results: > > $ ./scripts/bloat-o-meter vmlinux7.2-rc3_before.o vmlinux7.2-rc3_after.o > add/remove: 0/0 grow/shrink: 133/93 up/down: 5914901/-14344137 (-8429236) > < ... 227 lines redacted > > Total: Before=2641674349, After=2633245113, chg -0.32% > > (done on v7.2-rc3 with GCC 15.3.0 on an x86_64 defconfig) > > Upon analysis, this change in size can be tracked down to places where > container_of() is used in combination with __builtin_constant_p(). > > Here is a minimal reproducer: > > struct foo { > int a; > }; > > #define to_foo(a_ptr) container_of(a_ptr, struct foo, a) > > int f(int *a) > { > return __builtin_constant_p(to_foo(a)->a) || a; > } > > The assembly code before this series...: > > xor eax, eax > test rdi, rdi > setne al > ret > > ...and after: > > mov eax, 1 > ret > > Link: https://godbolt.org/z/fenbGexjY > > __builtin_constant_p(to_foo(a)->a) evaluates to false but gives the > optimiser the hint that pointer a is not NULL because of the > assumption that no undefined behaviour occurs. With this, the > expression: > > __builtin_constant_p(to_foo(a)->a) || a > > could be evaluated as true by the optimiser. > > But the small variation in container_of() makes it that the optimiser > currently misses this optimisation but manages to do it after the > simplification of patch #3 of this series. > > When __builtin_constant_p()'s argument is not trivially a compile time > constant, the result of __builtin_constant_p() comes late in the > evaluation process. And if it comes too late, after some other > optimisations were already done, the compiler will not retry and simply > miss these optimisations. > > Note that the above example is very fragile and the results shown in > the godbolt link might not be reproducible under very small > variations. > > Signed-off-by: Vincent Mailhol "fun" thing is, clang gets this right without your change, so this only seems to help the gcc users. Anyway, very nice optimizations, thanks for this! I'll queue these up later today. greg k-h