From 3938fa39fb263ffb23ec3f3f9c6849709fbeb469 Mon Sep 17 00:00:00 2001
From: Peter Jung <admin@ptr1337.dev>
Date: Sat, 20 Jan 2024 14:03:01 +0100
Subject: [PATCH] Add extra GCC optimization flags

Enable 2 extra optimimization flags:
  -fivopts
     Perform induction variable optimizations (strength reduction,
     induction variable merging and induction variable elimination)
     on trees.
  -fmodulo-sched
     Perform swing modulo scheduling immediately before the first
     scheduling pass. This pass looks at innermost loops and reorders
     their instructions by overlapping different iterations.

stress-ng microbenchmark improvements (average from 10 x 1min runs) on
Alderlake with gcc 13.2.0:
  af-alg:  1.0% (kernel AF_ALG crypto)
  pipe:    1.5% (pipe + context switch)
  fork:    4.4% (process fork/exit)
  mmap:    3.0% (memory mapping)
  switch:  4.9% (context switching)

KVM QEMU bootspeed improvements (based on average of 100 boots): 0.5%

Signed-off-by: Peter Jung <admin@ptr1337.dev>
---
 arch/x86/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/Makefile b/arch/x86/Makefile
index b7717a5e10ed..7302712d94e2 100644
--- a/arch/x86/Makefile
+++ b/arch/x86/Makefile
@@ -67,7 +67,7 @@ export BITS
 #
 #    https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53383
 #
-KBUILD_CFLAGS += -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx
+KBUILD_CFLAGS += -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -mno-avx2 -mno-avx512f -fno-tree-vectorize -fivopts -fmodulo-sched
 KBUILD_RUSTFLAGS += -Ctarget-feature=-sse,-sse2,-sse3,-ssse3,-sse4.1,-sse4.2,-avx,-avx2
 
 ifeq ($(CONFIG_X86_KERNEL_IBT),y)
-- 
2.43.0

