From f5759c25a0ccbf8cf33ba661d5c6839259bc1d61 Mon Sep 17 00:00:00 2001 From: Frogging-Family From: damachine Date: Wed, 15 Apr 2026 21:55:26 +0200 Subject: [PATCH] Add compiler optimization option Add CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3 Kconfig option that allows building the kernel with -O3 instead of the default -O2. Enable swing modulo scheduling (-fmodulo-sched, -fmodulo-sched-allow-regmoves, -fivopts) for additional loop optimization by overlapping iterations of innermost loops. Enable LLVM pipeliner (-mllvm -enable-pipeliner) for additional loop pipelining on supported targets. Signed-off-by: damachine --- Makefile | 9 +++++++++ init/Kconfig | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/Makefile b/Makefile index 36d0a32fb..510119afd 100644 --- a/Makefile +++ b/Makefile @@ -893,11 +893,20 @@ KBUILD_CFLAGS += -fno-delete-null-pointer-checks ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE KBUILD_CFLAGS += -O2 KBUILD_RUSTFLAGS += -Copt-level=2 +else ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3 +KBUILD_CFLAGS += -O3 +KBUILD_RUSTFLAGS += -Copt-level=3 else ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE KBUILD_CFLAGS += -Os KBUILD_RUSTFLAGS += -Copt-level=s endif +# Perform swing modulo scheduling immediately before the first scheduling pass. +# This pass looks at innermost loops and reorders their instructions by +# overlapping different iterations. +KBUILD_CFLAGS += $(call cc-option,-fmodulo-sched -fmodulo-sched-allow-regmoves -fivopts) +KBUILD_CFLAGS += $(call cc-option,-mllvm -enable-pipeliner) + # Always set `debug-assertions` and `overflow-checks` because their default # depends on `opt-level` and `debug-assertions`, respectively. KBUILD_RUSTFLAGS += -Cdebug-assertions=$(if $(CONFIG_RUST_DEBUG_ASSERTIONS),y,n) diff --git a/init/Kconfig b/init/Kconfig index 7484cd703..a9975a9bd 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1582,6 +1582,12 @@ config CC_OPTIMIZE_FOR_PERFORMANCE with the "-O2" compiler flag for best performance and most helpful compile-time warnings. +config CC_OPTIMIZE_FOR_PERFORMANCE_O3 + bool "Optimize more for performance (-O3)" + help + Choosing this option will pass "-O3" to your compiler to optimize + the kernel yet more for performance. + config CC_OPTIMIZE_FOR_SIZE bool "Optimize for size (-Os)" help -- 2.53.0