Re: [PATCH -tip] compiler_types.h: Optimize __unqual_scalar_typeof compilation time

From: Arnd Bergmann
Date: Wed May 27 2020 - 07:27:12 EST


On Wed, May 27, 2020 at 12:33 PM Marco Elver <elver@xxxxxxxxxx> wrote:
>
> If the compiler supports C11's _Generic, use it to speed up compilation
> times of __unqual_scalar_typeof(). GCC version 4.9 or later and
> all supported versions of Clang support the feature (the oldest
> supported compiler that doesn't support _Generic is GCC 4.8, for which
> we use the slower alternative).
>
> The non-_Generic variant relies on multiple expansions of
> __pick_integer_type -> __pick_scalar_type -> __builtin_choose_expr,
> which increases pre-processed code size, and can cause compile times to
> increase in files with numerous expansions of READ_ONCE(), or other
> users of __unqual_scalar_typeof().
>
> Summary of compile-time benchmarking done by Arnd Bergmann [1]:
>
> <baseline normalized time> clang-11 gcc-9
> this patch 0.78 0.91
> ideal 0.76 0.86
>
> [1] https://lkml.kernel.org/r/CAK8P3a3UYQeXhiufUevz=rwe09WM_vSTCd9W+KvJHJcOeQyWVA@xxxxxxxxxxxxxx
>
> Further compile-testing done with:
> gcc 4.8, 4.9, 5.5, 6.4, 7.5, 8.4;
> clang 9, 10.
>
> Reported-by: Arnd Bergmann <arnd@xxxxxxxx>
> Signed-off-by: Marco Elver <elver@xxxxxxxxxx>

This gives us back 80% of the performance drop on clang, and 50%
of the drop I saw with gcc, compared to current mainline.

Tested-by: Arnd Bergmann <arnd@xxxxxxxx>