GCC Newspaper
JUNE 15, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
match.pd Performance Win

Simplify conditional additions involving constants and vectors.

GCC simplifies conditional expressions of the form 'x != CST1 ? x + CST2 : CST3' to 'x + CST2' when CST1 + CST2 == CST3, including uniform vectors.

This patch extends GCC’s pattern matching to simplify conditional addition expressions. When the condition is of the form x != CST1 ? x + CST2 : CST3 and CST1 + CST2 == CST3, the expression is simplified to x + CST2. This handles cases with a third constant and uniform vectors, resolving a missing vector addition fold. New test cases have been added to verify the simplification for both scalar and vector types.

In Details

The match.pd file in GCC defines pattern-matching rules for simplifying expressions during compilation. This patch extends an existing rule to handle conditional additions with constants and uniform vectors. Specifically, it transforms x != CST1 ? x + CST2 : CST3 to x + CST2 when CST1 + CST2 == CST3. This optimization occurs during tree-ssa optimization.

For Context

During compilation, GCC performs various optimizations to improve code efficiency. One technique is pattern matching, where the compiler identifies specific code patterns and replaces them with simpler, equivalent forms. This commit adds a new pattern-matching rule to simplify conditional addition expressions where the result is equivalent to a simple addition. This simplification applies to both scalar values and uniform vectors (vectors where all elements have the same value).

Filed Under: optimizationpattern matchingvectorization