From ff052d5c684c0aec82110a9e4168d3b6bdb2ad1e Mon Sep 17 00:00:00 2001 From: Jash Date: Sun, 8 Nov 2026 15:37:41 +0530 Subject: [PATCH] perf: build zm_zone.cpp with gcc's dynamic vector cost model so motion detection vectorizes at -O2, fixes #5482 --- src/CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dffa371faa..2dc43b8d47 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -143,6 +143,12 @@ if(GSOAP_FOUND) endif() +# GCC 12+ only vectorizes with its very-cheap cost model at -O2, which leaves the +# per-pixel motion detection loop in zm_zone.cpp scalar in Release builds. +if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + set_source_files_properties(zm_zone.cpp PROPERTIES COMPILE_OPTIONS "-fvect-cost-model=dynamic") +endif() + # A fix for cmake recompiling the source files for every target. add_library(zm STATIC ${ZM_BIN_SRC_FILES})