GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
tree-optimization

Canonicalize conditional signed narrow clips to fix RISC-V saturation patterns.

Canonicalizes conditional signed narrow clips to ensure correct saturation behavior for RISC-V targets.

This change canonicalizes conditional signed narrow clip operations before loop if-conversion. The original form could lead to undefined behavior with signed minimum values and was being incorrectly transformed into saturating truncations. The new form ensures that the original overflow semantics are preserved when specific conditions like -fwrapv or sanitization are in effect, restoring correct saturation patterns for RISC-V tests.

In Details

Canonicalizes conditional signed narrow clips in tree-ssa, specifically (NT) ((UT) x > NT_MAX ? (-x) >> (PREC - 1) : x), to (NT) MIN ((UT) MAX (x, 0), NT_MAX). This is done before loop if-conversion to preserve the original overflow semantics, especially for RISC-V targets where certain negations might otherwise be misinterpetered as saturating truncations. This ensures correct handling of signed minimums and avoids issues with unsigned conversions or negations.

For Context
tree-ssa
Static Single Assignment form applied to GCC's Gimple intermediate representation. It simplifies many optimizations by ensuring each variable is assigned exactly once.
loop if-conversion
An optimization that replaces conditional branches within a loop with conditional move instructions, enabling better instruction-level parallelism.
saturation
In arithmetic operations, saturation means clamping the result to the maximum or minimum representable value if an overflow or underflow occurs, rather than wrapping around.
RISC-V
An open-standard instruction set architecture based on open RISC principles, known for its modularity and extensibility.
Filed Under: optimizationrisc-vcompiler