GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
i386 Performance Win

Cost scalar division by a constant as its expansion

Improves vectorization profitability by accurately costing scalar divisions by constants.

The i386 backend now more accurately costs scalar integer divisions and modulo operations when the divisor is a constant. Previously, these operations were always costed as a full divide instruction, even if they could be expanded to cheaper shifts or multiplications. This change prevents incorrect profitability estimates during vectorization, allowing for better optimization decisions.

In Details

The ix86_vector_costs::add_stmt_cost function in i386.cc previously charged the full DIV instruction cost for scalar TRUNC_DIV_EXPR, TRUNC_MOD_EXPR, and EXACT_DIV_EXPR, even when the divisor was a non-zero constant. This commit introduces ix86_const_divmod_cost to approximate the cost of expand_divmod in expmed.cc, providing a more accurate cost for these optimized scalar operations during SLP vectorization analysis.

For Context
vectorization
The process of transforming code that operates on single data elements into code that operates on multiple data elements simultaneously, often using SIMD (Single Instruction, Multiple Data) instructions for performance gains.
SLP vectorization
Short for Slanted-Line-Projector, a specific type of automatic vectorization that identifies opportunities to vectorize straight-line code segments (basic blocks).
TRUNC_DIV_EXPR
An intermediate representation (IR) expression representing a truncated integer division.
TRUNC_MOD_EXPR
An intermediate representation (IR) expression representing a truncated integer modulo operation.
EXACT_DIV_EXPR
An intermediate representation (IR) expression representing an exact integer division (no truncation).
Filed Under: i386optimizationvectorization