GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
phiopt Performance Win

phiopt: Add TARGET_MEM_REF support to factoring of loads.

Improves load factoring optimization by supporting `TARGET_MEM_REF` on certain memory accesses.

This commit enhances the factor_out_conditional_load optimization pass in GCC by adding support for TARGET_MEM_REF, which represents memory references with target-specific constraints. Previously, this optimization could not handle TARGET_MEM_REF instances, leading to less optimal code generation. The update allows the pass to factor out loads that use TARGET_MEM_REF under specific conditions, improving generated code quality and achieving comparable performance to LLVM for certain benchmarks.

In Details

The tree-ssa-phiopt.cc pass factor_out_conditional_load aims to hoist loads out of conditional branches. It previously lacked support for TARGET_MEM_REF, a specialized form of MEM_REF used for target-specific memory addressing. This patch introduces basic support by requiring that the index, step, and index2 operands of the TARGET_MEM_REF are identical, and optionally allows matching against a MEM_REF if the TARGET_MEM_REF has null index/step and index2 operands. A new test case factor_op_phi-load-target_mem-1.c is added.

For Context
phiopt
A GCC optimization pass that deals with PHI nodes, often related to optimizing control flow and data dependencies, particularly in SSA form.
load factoring
An optimization technique that hoists memory load operations out of conditional blocks to a point before the condition is evaluated, thereby reducing redundant loads.
TARGET_MEM_REF
A GCC internal representation for memory references that incorporates target-specific addressing modes or constraints, extending the generic MEM_REF.
PHI node
In Static Single Assignment (SSA) form, a PHI node is used at the join of control flow paths to merge values from different predecessors.
SSA form
Static Single Assignment form. An intermediate representation within GCC that simplifies many optimizations by ensuring each variable is assigned exactly once.
Filed Under: optimizationphiopttree-ssa