From c2281a7875096a1e7e375721bc16c0bd78fcdf6c Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Thu, 21 May 2026 15:21:00 -0400 Subject: [PATCH 1/2] Better guard release only compiler flags Signed-off-by: Juan Cruz Viotti --- cmake/common/compiler/options.cmake | 40 +++++++++++++++++++---------- 1 file changed, 27 insertions(+), 13 deletions(-) diff --git a/cmake/common/compiler/options.cmake b/cmake/common/compiler/options.cmake index 37754283d..763d17627 100644 --- a/cmake/common/compiler/options.cmake +++ b/cmake/common/compiler/options.cmake @@ -1,3 +1,13 @@ +# Applies the shared compiler defaults to at . +# +# Flag categories handled here: +# - Diagnostics (-W...): always on, every config +# - Language semantics (-fwrapv, -fstrict-aliasing, -fno-rtti on GCC): always on +# - Optimization-related (loop unrolling, vectorization, fast-math relaxations): +# gated to non-Debug configs because they have no effect at -O0 but still +# cost Clang/GCC pipeline time +# +# Do not add optimization-only flags here without a generator-expression gate function(sourcemeta_add_default_options visibility target) if(SOURCEMETA_COMPILER_MSVC) # See https://learn.microsoft.com/en-us/cpp/build/reference/compiler-options-listed-by-category @@ -40,22 +50,26 @@ function(sourcemeta_add_default_options visibility target) $<$,$>:-Wnon-virtual-dtor> $<$,$>:-Woverloaded-virtual> $<$,$>:-Winvalid-offsetof> - -funroll-loops + # Semantics, not optimization: keep on for every config -fstrict-aliasing - -ftree-vectorize - - # To improve how much GCC/Clang will vectorize - -fno-math-errno - -fno-trapping-math - -fno-signed-zeros - -freciprocal-math - -fassociative-math - # Assume that signed arithmetic overflow of addition, subtraction and # multiplication wraps around using twos-complement representation # See https://users.cs.utah.edu/~regehr/papers/overflow12.pdf # See https://www.postgresql.org/message-id/1689.1134422394@sss.pgh.pa.us - -fwrapv) + -fwrapv + + # Optimization-only: emitted only when not building Debug. At -O0 these + # run analyses that never reach codegen, costing build time for no + # behavioral effect + $<$>:-funroll-loops> + $<$>:-ftree-vectorize> + + # Fast-math relaxations: only meaningful with -O1+ vectorization + $<$>:-fno-math-errno> + $<$>:-fno-trapping-math> + $<$>:-fno-signed-zeros> + $<$>:-freciprocal-math> + $<$>:-fassociative-math>) endif() if(SOURCEMETA_COMPILER_LLVM) @@ -81,9 +95,9 @@ function(sourcemeta_add_default_options visibility target) -Wrange-loop-analysis # Enable loop vectorization for performance reasons - -fvectorize + $<$>:-fvectorize> # Enable vectorization of straight-line code for performance - -fslp-vectorize) + $<$>:-fslp-vectorize>) elseif(SOURCEMETA_COMPILER_GCC) target_compile_options("${target}" ${visibility} # Newer versions of GCC (i.e. 14) seem to print a lot of false-positives here From c3d049186f592e06f735e5c85437ce0d90bfab6c Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Thu, 21 May 2026 15:31:41 -0400 Subject: [PATCH 2/2] Fix Signed-off-by: Juan Cruz Viotti --- cmake/common/compiler/options.cmake | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/cmake/common/compiler/options.cmake b/cmake/common/compiler/options.cmake index 763d17627..d43bb2d91 100644 --- a/cmake/common/compiler/options.cmake +++ b/cmake/common/compiler/options.cmake @@ -57,19 +57,21 @@ function(sourcemeta_add_default_options visibility target) # See https://users.cs.utah.edu/~regehr/papers/overflow12.pdf # See https://www.postgresql.org/message-id/1689.1134422394@sss.pgh.pa.us -fwrapv + # Fast-math relaxations relax IEEE conformance (errno after math.h, + # signed-zero handling, reassociation), so they affect observable + # behavior and must apply to every config to keep Debug and Release + # semantics aligned + -fno-math-errno + -fno-trapping-math + -fno-signed-zeros + -freciprocal-math + -fassociative-math # Optimization-only: emitted only when not building Debug. At -O0 these # run analyses that never reach codegen, costing build time for no # behavioral effect $<$>:-funroll-loops> - $<$>:-ftree-vectorize> - - # Fast-math relaxations: only meaningful with -O1+ vectorization - $<$>:-fno-math-errno> - $<$>:-fno-trapping-math> - $<$>:-fno-signed-zeros> - $<$>:-freciprocal-math> - $<$>:-fassociative-math>) + $<$>:-ftree-vectorize>) endif() if(SOURCEMETA_COMPILER_LLVM)