GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
cselim

cselim: Improve conditional store replacement with skipping support

Enhances cselim's conditional store replacement to handle cases with stores on either side of a branch.

This commit improves the cond_if_else_store_replacement_limited optimization in GCC’s cselim pass. It now supports skipping the replacement when a store operation exists on either side of the conditional branch, provided these stores do not interfere with other operations. This change was motivated by code generation for std::optional::reset and adds new test cases.

In Details

The cselim pass's cond_if_else_store_replacement_limited function is enhanced to support skipping replacement when a store exists on either side of the conditional branch. This complements existing logic for handling stores that don't interfere with other stores. The trailing_store_in_bb helper was simplified to require a simple assignment store, ensuring correctness when skipping stores in conditional contexts.

For Context
cselim
Conditional Select Elimination, a GCC optimization pass that simplifies conditional code, often by replacing conditional branches with select operations.
tree-ssa
The SSA (Static Single Assignment) form used internally by GCC for performing optimizations. The 'tree' part refers to GCC's intermediate representation.
gimple
GCC's Gimple Intermediate Representation, a lower-level, three-address code form used after the SSA phase for further optimization.
std::optional
A C++17 feature providing a type-safe union with a distinguished null state, often used to represent values that may or may not be present.
Filed Under: optimizationcselimtree-ssacompiler