From ee63d8dd8ccdb19d8536f95e0e5e0857c9f1f940 Mon Sep 17 00:00:00 2001 From: Florian Engelhardt Date: Wed, 3 Sep 2025 15:12:20 +0200 Subject: [PATCH 1/2] add details about optimizer passes --- reference/opcache/ini.xml | 153 +++++++++++++++++++++++++++++++++++++- 1 file changed, 149 insertions(+), 4 deletions(-) diff --git a/reference/opcache/ini.xml b/reference/opcache/ini.xml index 1ffeea399538..47345b759185 100644 --- a/reference/opcache/ini.xml +++ b/reference/opcache/ini.xml @@ -592,10 +592,155 @@ A bitmask that controls which optimisation passes are executed. - The default is to apply all safe optimizations. - Changing the default is mostly useful for debugging/developing the optimizer - (see also opcache.opt_debug_level). - + The default value is 0x7FFEBFFF, which enables all + safe optimizations. Disabling optimizations or enabling unsafe optimizations + is mostly useful for debugging/developing the optimizer. + + + Each bit in the bitmask enables a specific optimization pass: + + + Optimization Pass Bitmask + + + + Bit + Pass Name + Description + Default + + + + + 0 + PASS_1 + Simple local optimizations: constant substitution, expression evaluation, conditional JMP optimization + On + + + 1 + PASS_2 + Reserved - unused since PHP 7.4 - as functionality got merged into PASS_1 + On + + + 2 + PASS_3 + Jump optimization: optimizes series of JMPs + On + + + 3 + PASS_4 + Function call optimization: INIT_FCALL_BY_NAME to DO_FCALL conversion + On + + + 4 + PASS_5 + CFG optimization: Control Flow Graph based optimization + On + + + 5 + PASS_6 + DFA optimization: Data Flow Analysis based optimization + On + + + 6 + PASS_7 + Call graph optimization: whole-script optimization using call graph + On + + + 7 + PASS_8 + SCCP: Sparse Conditional Constant Propagation + On + + + 8 + PASS_9 + TMP VAR optimization: optimize temporary variable usage + On + + + 9 + PASS_10 + NOP removal: remove no-operation instructions + On + + + 10 + PASS_11 + Merge equal constants: compact literals table + On + + + 11 + PASS_12 + Adjust stack size: optimize function call stack size + On + + + 12 + PASS_13 + Remove unused variables: remove compiled variables that are never used + On + + + 13 + PASS_14 + DCE: Dead Code Elimination + On + + + 14 + PASS_15 + Collect constants: aggressive constant collection (unsafe) + Off + + + 15 + PASS_16 + Inline functions: function inlining optimization + On + + + 16 + (Flag) + Ignore overloading: assume no operator overloading (unsafe). Not a pass; modifies optimizer behavior + Off + + + +
+ + Safe vs Unsafe Optimizations + + Safe optimizations (enabled by default) preserve the exact + behavior of PHP code while improving performance. They include dead code elimination, + constant folding, and jump optimization. + + + Unsafe optimizations (disabled by default) may alter behavior + in edge cases: + + + + + Bit 14: Aggressive constant collection may not preserve + exact behavior in all edge cases + + + + + Bit 16: Ignoring operator overloading + + + +
From e4cb04032362ca1dd8ab8a63a0cba2db5df14cee Mon Sep 17 00:00:00 2001 From: Florian Engelhardt Date: Thu, 4 Sep 2025 10:46:29 +0200 Subject: [PATCH 2/2] update from review --- reference/opcache/ini.xml | 53 ++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 20 deletions(-) diff --git a/reference/opcache/ini.xml b/reference/opcache/ini.xml index 47345b759185..67ec0550ffcb 100644 --- a/reference/opcache/ini.xml +++ b/reference/opcache/ini.xml @@ -614,103 +614,103 @@ 0 PASS_1 - Simple local optimizations: constant substitution, expression evaluation, conditional JMP optimization + Simple peephole optimizations On 1 PASS_2 - Reserved - unused since PHP 7.4 - as functionality got merged into PASS_1 + Unused (got merged into PASS_1) On 2 PASS_3 - Jump optimization: optimizes series of JMPs + Simple jump optimization On 3 PASS_4 - Function call optimization: INIT_FCALL_BY_NAME to DO_FCALL conversion + Call optimization On 4 PASS_5 - CFG optimization: Control Flow Graph based optimization + Control Flow Graph based optimization On 5 PASS_6 - DFA optimization: Data Flow Analysis based optimization + Data Flow Analysis based optimization On 6 PASS_7 - Call graph optimization: whole-script optimization using call graph + Whether call graph should be used for SSA-based optimizations On 7 PASS_8 - SCCP: Sparse Conditional Constant Propagation + Sparse conditional constant propagation On 8 PASS_9 - TMP VAR optimization: optimize temporary variable usage + Temporary variable optimization On 9 PASS_10 - NOP removal: remove no-operation instructions + Removal of NOP opcodes On 10 PASS_11 - Merge equal constants: compact literals table + Literal optimization On 11 PASS_12 - Adjust stack size: optimize function call stack size + Call stack adjustment On 12 PASS_13 - Remove unused variables: remove compiled variables that are never used + Unused variable removal On 13 PASS_14 - DCE: Dead Code Elimination + Dead code elimination On 14 PASS_15 - Collect constants: aggressive constant collection (unsafe) + Collect and substitute constant declarations (unsafe) Off 15 PASS_16 - Inline functions: function inlining optimization + Trivial function inlining (part of call optimization) On 16 (Flag) - Ignore overloading: assume no operator overloading (unsafe). Not a pass; modifies optimizer behavior + Ignore possibility of operator overloading (unsafe) Off @@ -731,7 +731,7 @@ Bit 14: Aggressive constant collection may not preserve - exact behavior in all edge cases + exact behavior in all cases @@ -988,8 +988,21 @@ Produces opcode dumps for debugging different stages of optimizations. - 0x10000 will output opcodes as the compiler produced them before any optimization occurs - while 0x20000 will output optimized codes. + Accepts bit flags from + opcache.optimization_level for optimization passes, plus + additional debugging dump points: + + + 0x10000: Dump before optimizer + 0x20000: Dump after optimizer + 0x40000: Dump before CFG optimizations + 0x80000: Dump after CFG optimizations + 0x200000: Dump before SSA optimizations + 0x400000: Dump after SSA optimizations + + + Setting opcache.opt_debug_level=-1 produces a full trace + through all optimization stages.