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

Add RTX costs for `if_then_else' expressions

Adds cost information for `if_then_else` expressions in LoongArch to enable better if-conversion optimizations.

The LoongArch backend now defines cost information for if_then_else expressions. Without this, the middle-end estimates the cost conservatively. By assigning a cost of a single machine cycle (ignoring branch costs), this change aims to encourage more aggressive if-conversion optimizations, where conditional logic is converted into predicated instructions.

In Details

The loongarch_rtx_costs function has been updated to include an entry for IF_THEN_ELSE. Previously, the middle-end would provide a generic estimate for this construct, assuming a cost of 3 instructions (12 units). By defining a specific, low cost (1 machine cycle, ignoring the branch taken cost), the backend now signals to the middle-end that if_then_else structures are cheap. This encourages the middle-end's if-conversion passes to transform conditional branches into predicated instructions where beneficial.

For Context
LoongArch
A RISC instruction set architecture developed in China, designed for high performance and efficiency. GCC has a backend for this architecture.
RTX
Representation Tree. GCC's internal intermediate representation for code, used after parsing and before machine code generation.
if_then_else
A conditional construct in GCC's intermediate representation (RTX) that represents an if-then-else statement or a conditional expression.
cost information
Estimates of the execution cost (in terms of cycles, instructions, or other metrics) for various operations or constructs, used by compiler optimization passes.
if-conversion
An optimization technique that transforms conditional control flow (if-statements, branches) into predicated instructions or conditional moves, potentially improving instruction-level parallelism.
backend
The part of the compiler responsible for generating machine code for a specific target architecture.
middle-end
The part of the compiler that performs optimizations on the intermediate representation (IR) of the code, independent of the target architecture.
Filed Under: loongarchoptimizationif-conversion