From 33054ddd51e0b1e326c6bed02dfb7637dce2cfd7 Mon Sep 17 00:00:00 2001 From: Brandt Bucher Date: Sat, 28 Jun 2025 08:41:00 -0700 Subject: [PATCH 1/2] -Os --- Tools/jit/_targets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tools/jit/_targets.py b/Tools/jit/_targets.py index ed10329d25d2f9..69185a6b5984b8 100644 --- a/Tools/jit/_targets.py +++ b/Tools/jit/_targets.py @@ -137,7 +137,7 @@ async def _compile( f"-I{CPYTHON / 'Include' / 'internal' / 'mimalloc'}", f"-I{CPYTHON / 'Python'}", f"-I{CPYTHON / 'Tools' / 'jit'}", - "-O3", + "-Os", "-S", # Shorten full absolute file paths in the generated code (like the # __FILE__ macro and assert failure messages) for reproducibility: From dbca451a9d6f81d833920c67ba4b01ad6bcb8dc8 Mon Sep 17 00:00:00 2001 From: Brandt Bucher Date: Sun, 6 Jul 2025 15:38:27 -0700 Subject: [PATCH 2/2] Add comment explaining -Os --- Tools/jit/_targets.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Tools/jit/_targets.py b/Tools/jit/_targets.py index 69185a6b5984b8..728f48128ce79c 100644 --- a/Tools/jit/_targets.py +++ b/Tools/jit/_targets.py @@ -137,6 +137,14 @@ async def _compile( f"-I{CPYTHON / 'Include' / 'internal' / 'mimalloc'}", f"-I{CPYTHON / 'Python'}", f"-I{CPYTHON / 'Tools' / 'jit'}", + # -O2 and -O3 include some optimizations that make sense for + # standalone functions, but not for snippets of code that are going + # to be laid out end-to-end (like ours)... common examples include + # passes like tail-duplication, or aligning jump targets with nops. + # -Os is equivalent to -O2 with many of these problematic passes + # disabled. Based on manual review, for *our* purposes it usually + # generates better code than -O2 (and -O2 usually generates better + # code than -O3). As a nice benefit, it uses less memory too: "-Os", "-S", # Shorten full absolute file paths in the generated code (like the